일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | |||
5 | 6 | 7 | 8 | 9 | 10 | 11 |
12 | 13 | 14 | 15 | 16 | 17 | 18 |
19 | 20 | 21 | 22 | 23 | 24 | 25 |
26 | 27 | 28 | 29 | 30 | 31 |
Tags
- android ImageLoad
- 부산에서 창원
- 자전거
- 로드바이크
- android facebook
- 자바
- 구포에서 자전거
- 구조체
- 낙동강 종주
- elk stack
- 부산에서 창원 자전거
- NetworkImageView
- android imageView zoom
- 창원에서 부산
- 안드로이드 이미지 로드
- c언어 구조체
- laravel
- spring
- C언어
- workbench
- mysql
- android loadImage
- image zoom
- 삼량진 자전거
- spring boot
- httpclient post
- volley
- ImageLoad
- 삼량진
- 구포에서 삼량진
Archives
- Today
- Total
은근한
Spring boot Mybatis Mapper with XML 본문
resources 내에 mybatis 폴더를 만들고
mybatis 내의 mapper 폴더를 생성해서 xml 파일을 관리할 예정이다.
Mybatis Mapper Xml에 사용될 DTD (Document Type Definition)
<?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="kaonashi.ryoko.TestMapper">
<select id="getCurrentDateTime" parameterType="String" resultType="String">
ex) select NOW()
</select>
</mapper>
namespace에는 Mapper Interface를 적어주게 되면
Interface 내의 Method Name 과 Xml내의 id 값이 일치하면 자동으로 맵핑 시켜준다.
*namespace가 헷갈릴수도 있는데 xml이 아닌 interface위치를 맵핑시켜주면 된다.
application.properties
#Mybatis
mybatis.type-aliases-package=kaonashi.ryoko
mybatis.mapper-locations=mybatis/mapper/**/*.xml
패키지는 alias 묶어서 조금 더 보기 편하게 만드려고 했고
관리하는 mapper 폴더를 지정해줬다.
TestMapper.java
import org.apache.ibatis.annotations.Mapper;
@Mapper
public interface TestMapper {
String getCurrentDateTime();
}
사용하고자 하는 곳에서 @Autowired
@Autowired TestMapper testMapper;