Mybstis 子查詢遞歸


實體類:添加字段 :
 private List<NjgbOtherDic> children;
mapper.xml :

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.jianfan.mapper.NjgbOtherDicMapper">

    <!-- 通用查詢映射結果 -->
    <resultMap id="BaseResultMap" type="com.jianfan.entity.NjgbOtherDic">
        <result column="ID" property="id" />
        <result column="TYPENAME" property="typename" />
        <result column="DICNAME" property="dicname" />
        <result column="PARENTID" property="parentid" />
        <result column="ORDERKEY" property="orderkey" />
        <result column="CREATER" property="creater" />
        <result column="CREATETIME" property="createtime" />
        <collection property="children" ofType="NjgbOtherDic" column="ID" select="findByParentId"/>
    </resultMap>

    <!-- 通用查詢結果列 -->
    <sql id="Base_Column_List">
        ID, TYPENAME, DICNAME, PARENTID, ORDERKEY, CREATER, CREATETIME
    </sql>

    <select id="findlist" resultMap="BaseResultMap">
        select * from NJGB_OTHER_DIC where PARENTID=0
    </select>
    <select id="findByParentId" resultMap="BaseResultMap">
        select * from NJGB_OTHER_DIC where PARENTID=#{id}
    </select>
</mapper>

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章