Mybatis Association, mybatisassociation

Source: Internet
Author: User

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.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.