Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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
- Firebase
- JavaScript
- FLUTTER
- Java
- tomcat
- Exception
- Kotlin
- jQuery
- Android Apk 이름 변경
- apache gzip
- html
- css
- R프로그래밍
- error
- release Apk
- Eclipse
- release unsigned
- Android
- Android Apk 이름
- MySQL
- Program type already present
- CSS사용법
- fragment
- 안드로이드
- spring
- java error
- DataTable
- Android Apk
- android error
- android fragment
Archives
- Today
- Total
selfstarter
MyBatis ResultMap Collection 사용법 본문
MyBatis ResultMap Collection 사용법
MyBatis ResultMap
-
어떤 vo에 관련된 정보를 가져오고 싶을 때 서브쿼리형식으로 가져올 수 있다.(서브쿼리와 달리 코드가 분리되어 코드가 단순해진다)
-
아래 예제는 User 클래스 안에 User의 캐릭터와 구매내역이 있다. User 정보 외에 다른 테이블 정보도 같이 가져와야한다.
-
User.java
public class User { private String name; ... private List<Map<String, Object>> characterList; private List<Map<String, Object>> cashBuyList; }
-
user_query.xml
<resultMap type="UserInfo" id="userInfo"> <collection column="userSeq= USER_SEQ" property="characterList" javaType="List" ofType="Map" select="getCharacterList"/> <collection column="userSeq= USER_SEQ" property="cashBuyList" javaType="List" ofType="Map" select="getBuyList"/> </resultMap>
SELECT NAME AS name .. WHERE userSeq = #{userSeq} ... WHERE userSeq = #{userSeq}
MyBatis resultMap
- type : 데이터 타입 - id : 데이터 타입의 변수명(호출한 쿼리에서 resultMap에 id명을 사용해야한다)
MyBatis collection
- column : 매개 변수의 값을 지정한다(getCharacterList 쿼리에 매개변수 #{userSeq}의 값을 USER_SEQ 컬럼의 값으로 설정한다)
- property : bean 안의 멤버변수명
- javaType : collection
- ofType : collection 안에 들어있는 데이터타입
- select : 실행할 쿼리문
resultMap에 GeneralDeployment을 호출하면 collection의 쿼리도 같이 실행된다
Comments