Spring - DB 연결

2023. 3. 14. 13:52Spring

DB연결을 위해 프로젝트 만들 때 아래 체크박스 6가지 체크해서 만들기.

application.properties에 포트 변경 코드와, 내용 변경 즉시 반영 코드,

데이터베이스 접속 정보 코드 추가

# tomcat port를 8081로 변경
server.port=8081

#thymeleaf로 그려진 화면이 변경되면 즉시 변경내용 적용.
spring.thymeleaf.cache=false

#데이터베이스 접속 정보
#spring.datasource.url=jdbc:oracle:thin:@127.0.0.1:1521/xe
#spring.datasource.driver-class-name=oracle.jdbc.OracleDriver
spring.datasource.driver-class-name=net.sf.log4jdbc.sql.jdbcapi.DriverSpy
spring.datasource.url=jdbc:log4jdbc:oracle:thin:@localhost:1521/xe
spring.datasource.username=MyDB
spring.datasource.password=ORACLE

#xml location
mybatis.mapper-locations=classpath:mappers/*.xml

build.gradle에 아래 코드 추가

implementation 'org.bgee.log4jdbc-log4j2:log4jdbc-log4j2-jdbc4:1.16' //쿼리 로그 라이브러리 추가

코드 추가 후 저장-프로젝트-오른쪽마우스-gradle-refresh 눌러줘야 로딩 됨.

 

프로젝트 밑 src/main/resources 밑에 파일 3개 붙여넣기.

mapper에서 아래 소스 클릭하면 쿼리문 치는 창 뜸.

GHL