您的位置:首页 > 其它

Mybatis Association

2015-08-30 14:25 351 查看
<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 (写得最好)

/article/1380942.html

http://cczakai.iteye.com/blog/1276722
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: