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>

你可能感兴趣的:(myBatis)