Mybatis Association, mybatisassociation
<ResultMap id = "cpBookCategoryResultMap"
Type = "busines. administer. cp. model. CPBookCategory">
<Result column = "id" property = "id"/>
<Result column = "name" property = "name"/>
<Result column = "pid" property = "pid"/>
<Result column = "is_parent" property = "isParent"/>
<Result column = "ctime" property = "ctime"/>
<Result column = "utime" property = "utime"/>
<Association property = "childList" column = "id" select = "getCategoryChildList"/>
</ResultMap>
<ResultMap id = "cpBookCategoryResultMap_2"
Type = "java. util. HashMap">
<Result column = "id" property = "id"/>
<Result column = "name" property = "name"/>
<Result column = "pid" property = "pid"/>
<Result column = "is_parent" property = "isParent" javaType = "boolean"/>
<Association property = "children" column = "id" select = "getCategoryChildList"/>
</ResultMap>
<Select id = "getCategoryChildList" resultMap = "cpBookCategoryResultMap_2">
<! [CDATA [
SELECT id, name, is_parent, pid FROM cp. tbl_cp_category where pid =#{ value };
]>
</Select>
Explanation: 1) the busines. administer. cp. model. CPBookCategory class has an attribute such as childList.
2) The childList attribute is a set and is obviously not a specific field in the database table. It is derived from the query result set of another table (based on the value of CPBookCategory id ).
3) Fill in the result set of the getCategoryChildList query to the childList attribute of busines. administer. cp. model. CPBookCategory and return
Refer:
Http://www.cnblogs.com/xdp-gacl/p/4264440.html (best written)
Http://blog.csdn.net/isea533/article/details/20868189
Http://cczakai.iteye.com/blog/1276722
Copyright Disclaimer: This article is an original article by the blogger and cannot be reproduced without the permission of the blogger.