2017-04-05 4 views
1

커스텀 매핑 :MyBatis로 나는이 같은 자바 빈을 정의한

public class Person{ 
    private int id; 
    private String name; 
    private Map<String, Object> properties; 
    // getters and setters ... 
} 

후속 쿼리 줄 : 나는 Person 클래스의에 "ID"와 "이름"열을 매핑 할

select id, name, age, address from users; 

을 "id"및 "name"속성을 사용하지만 "age"및 "address"열을 "properties"맵에 키 - 값 쌍으로 매핑합니다.

mybatis에서도 가능합니까? mybatis의 최신 버전을 사용하고 있습니다.

답변

0

당신이 무엇을 기대해야 다음은 암시 적 매핑 (열 -> 속성 이름 일치)와

<resultMap id="personResultMap" type="Person"> 
    <id property="id" column="id"/> 
    <result property="name" column="name"/> 
    <association property="properties" javaType="map"> 
    <result property="age" column="age"/> 
    <result property="address" column="address"/> 
</association> 
</resultMap> 

도 충분히있을 수 다음

<resultMap id="personResultMap" type="Person"> 
    <association property="properties" javaType="map" /> 
</resultMap>