728x90
SpringBoot 4.x 와 Mybatis 4.x 버전 사용
Mybatis 최초 연결시 체크리스트를 만들어 보았다.
1. application.yml 설정
mybatis:
mapper-locations: classpath:/mapper/**/*.xml #쿼리위치
type-aliases-package: com.example.test #xml에서의 파라미터, resultType 찾는 패키지
configuration: #카멜케이스
map-underscore-to-camel-case: true
jpa:
hibernate:
ddl-auto: create
mybatis 설정은 들여쓰기 없이 제일 왼쪽으로 붙여서 추가
2. @MapperScan 혹은 @Mapper 어노테이션 확인
@MapperScan은 전역으로 설정(저는 이렇게 진행하였습니다.)
@Mapper는 특정 매퍼 인터페이스만 설정
@MapperScan 예시
@SpringBootApplication
@MapperScan("com.example.test.*.mapper")
public class ErpApplication {
public static void main(String[] args) {
SpringApplication.run(ErpApplication.class, args);
}
}
@Mapper 예시
@Mapper
public interface TestMapper {
List<Employee> getTest();
}
둘중 택일을 해서 사용해야한다.
추가로 JPA와 함께 사용한다면 @MapperScan하는 패키지 대상에 JpaRepository Interface가 들어가면 안된다.
3. 인터페이스 생성(@MapperScan으로 진행하는 경우)
public interface TestMapper {
List<Employee> getTest();
}
4. mapper.xml 추가
/resources/mapper/test/TestMapper.xml
mapper의 파일명 규칙은 지켜주는 게 좋음.
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.example.test.user.mapper.TestMapper">
<select id="getTest">
select *
from test
</select>
</mapper>
<mapper> 태그 외에도 추가해주어야함
'서버' 카테고리의 다른 글
| Windos11 OS 설치시 USB인식 안되는 경우 (boot from efi file) (0) | 2026.05.23 |
|---|---|
| 외국 IP차단시 구글 검색결과 미노출 (synology or CloudFlare) (0) | 2026.05.22 |
| docker container mariadb 데이터 그대로 다른 서버에 옮기기 (0) | 2026.05.12 |
| 웹 서버 자동화 공격 방어2 - fail2ban 셋팅 (0) | 2026.05.07 |
| 웹 서버 자동화 공격 방어(Remote Command Execution (RCE) attack, nginx, cloudflare, fail2ban 셋팅) (1) | 2026.05.07 |