首页 > 其他 > 详细

Mybatis Association

时间:2015-08-30 15:57:09      阅读:154      评论:0      收藏:0      [点我收藏+]

<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>
    
    解释:1)busines.administer.cp.model.CPBookCategory这个类中有childList这样一个属性。
                2)这个属性childList是一个集合,显然不会是对应数据库表中的某一字段,它来源于另一张表(根据CPBookCategory的id的值作参数)的查询结果集
                3)将getCategoryChildList查询的结果集,填充到busines.administer.cp.model.CPBookCategory的childList属性中,返回

参考:

http://www.cnblogs.com/xdp-gacl/p/4264440.html (写得最好)

http://blog.csdn.net/isea533/article/details/20868189

http://cczakai.iteye.com/blog/1276722



版权声明:本文为博主原创文章,未经博主允许不得转载。

Mybatis Association

原文:http://blog.csdn.net/u010913106/article/details/48104491

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!