자세한 사항은 아래 URL 참고
https://mybatis.github.io/spring/index.html
1. MySQL 과 MyBatis 관련 library 설치
- pom.xml 에서 아래 dependency 추가
2. DispatcherServlet-context.xml 설정 (datasource, sqlSessionFactory)
3. 쿼리 결과를 담을 entity class 생성
4. 쿼리를 목록으로 하는 interface 생성
- src/main/java 에 위치
- @Select 와 같은 쿼리 annotation은 매핑되는 xml에 쿼리가 있는 경우 무시된다.
ex)
5. resultMap 과 쿼리를 목록으로 하는 xml 생성
- src/main/resources 에 위치하며, interface와 동일한 위치, 동일한 파일명을 가져야 한다.
- mapper namespace="src/main/resources 아래 xml 위치"
- resultMap type="src/main/java 아래 entity file 위치"
6. DispatcherServlet-context.xml 설정 (쿼리 xml)
7. java에서 쿼리 사용
- DispatcherServlet-context.xml 설정 (쿼리 xml 을 사용할 java 파일)
- java에서 사용
'Programming Practice > Spring' 카테고리의 다른 글
query XML 에서 사용하는 Vo(Entity) type 의 alias 지정 (0) | 2014.12.14 |
---|---|
Spring transaction 설정_MySQL (0) | 2014.12.14 |
Repository(Dao) 에서 SqlSession 사용_MySQL (0) | 2014.12.14 |
Dispatcher Servlet 설명 (0) | 2014.10.12 |
기본적인 pom.xml 설정 (0) | 2014.10.12 |