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
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
相关文章推荐
- 策略模式
- 欢迎使用CSDN-markdown编辑
- MongoDB (四) MongoDB 数据模型
- 算法篇——Cantor的数表
- 关于MVC4-5 添加EF controller时 EF为同级类库时,报错时的问题解决。
- TCP协议的一些问题
- HDOJ 4548 美素数
- JS数组
- disk boot info
- HDU1572-下沙小面的(2)-最短路(深搜)
- 为ESXi配置存储
- MongoDB (三) MongoDB 安装
- mac os x 端口转发(80)
- 物理地址和虚拟地址的区别
- HashSet
- win10怎样还原win7?win10一键还原win7图文教程
- 思科交换机密码配置和清除
- HDOJ 2544 最短路
- 关于IOS 的内存有优化问题
- PHP面向对象构造函数说明