카테고리 없음
spring boot + mybatis
히쑤우
2023. 3. 4. 23:35
gradle 기준으로 설명 하겠습니다.
1. application.properties 아래 코드 추가
# mapper.xml 위치 지정
mybatis.mapper-locations: mapper/*.xml
# model 프로퍼티 camel case 설정
mybatis.configuration.map-underscore-to-camel-case=true
# 패키지 명을 생략할 수 있도록 alias 설정
mybatis.type-aliases-package=com.temp
# mapper 로그레벨 설정
logging.level.com.azurealstn.codespringweb.mapper=TRACE
2. mapper 패키지 추가
- interface 생성 및 @Mapper 어노테이션 추가
- mybatis 없이 사용할 수 있음(@Select 어노테이션 사용)
- 다양한 데이터가 필요한 경우 List 형태로 메서드 작성
3. Mapper.xml 파일 추가
- resources 경로 내 mapper 폴더 추가 및 Mapper.xml 추가
- mapper 태그 내 namespace에 2번에서 추가했던 Mapper2 인터페이스 경로 작성
- select 태그 내 id는 Mapper2 인터페이스의 사용 할 메서드 작성
- resultType은 해당 메서드의 타입 형태
- 이 후 SQL문 작성