프로젝트/Spring Boot
Mybatis 적용
광박이
2022. 10. 11. 16:10
728x90
Mybatis
Mybatis는 객체지향 언어인 자바의 관계형 데이터베이스 프로그래밍을 좀 더 쉽게 할 수 있게 도와주는 개발 프레임워크이며, 복잡한 JDBC 코드를 걷어내며 깔끔한 소스코드를 유지, 자바의 객체(Object)와 SQL 사이에서 자동 맵핑을 도와주는 프레임워크로 XML 형태로 쓰인 JDBC 코드라고 생각해도 될 만큼 JDBC의 모든 기능을 제공합니다.
pom.xml - dependency 적용 :
pom.xml 파일에 mybatis-spring-boot-starter dependency를 적용합니다.
application.yml - mybatis 설정 코드 추가 :
### mybatis
mybatis:
# xml파일 result type에 패키지명을 생략할 수 있도록 alias 설정
type-aliases-package: 프로젝트 패키지
configuration:
# model 프로퍼티 camel case 설정
map-underscore-to-camel-case: true
# Mybatis mapper 위치 설정
mapper-locations:
- mapper/**/*.xml
Sample 코드 구조 :
src
└ main
├ java
| └ std
| └ pjt
| └ springboot
| └ sample
| ├ controller // Controller java class
| ├ service // Service java interface
| └ impl // Service java class
| ├ mapper // Mapper java class
| └ vo // VO or DTO
└ resources
└ mapper
└ sample // SQL.xml
Smaple 코드 작성 :
728x90