Mybatis 递归 出菜单栏

1.mapper 文件

<!--初始化菜单树-->
<resultMap id="DirectoryTree" type="com.rkinf.edrc.entity.ResDir">
    <result column="id" property="id" javaType="java.lang.String"></result>
    <result column="name" property="name" javaType="java.lang.String"></result>
    <result column="code" property="code" javaType="java.lang.String"></result>
    <result column="parent_id" property="parentId" javaType="java.lang.String"></result>
    <result column="description" property="description" javaType="java.lang.String"></result>

    <collection column="id" property="childrenList" ofType="com.rkinf.edrc.entity.ResDir" javaType="java.util.ArrayList" select="selectDirectoryChildrenByParentId"></collection>
</resultMap>
<!--先查询菜单根目录-->
<!--这里的返回结果必须为resultMap,并且为上面构建resultMap的id值-->
<select id="getDirectoryList" resultMap="DirectoryTree">
    SELECT * FROM T_SJZX_META_DATA_DIRECTORY d WHERE d.parent_id =''
</select>

<!--再次利用上次查询的collection 中的column的值 cid 做递归查询,查询所有子菜单-->
<!-- 这里的返回结果必须为resultMap,并且值为上面构建的resultMap的id的值 -->
<select id="selectDirectoryChildrenByParentId" resultMap="DirectoryTree">
    SELECT * FROM  T_SJZX_META_DATA_DIRECTORY WHERE parent_id = #{parentId}
</select>

2.实体类

private  childrenList

猜你喜欢

转载自blog.csdn.net/qq_38233650/article/details/88747226