Mybatis 使用 SQL 递归获取单表中的树结构

  • xml 代码
<resultMap type="xxx.xxx.xxx.xxx.实体类" id="xxxListTree">
        <result column="id" property="id" javaType="java.lang.Long" />
        <result column="xxx_name" property="xxxName" javaType="java.lang.String" />
        <result column="parent_id" property="parentId" javaType="java.lang.Long" />
        <result column="create_user" property="createUser" javaType="java.lang.Long" />
<!--        <collection column="{id=id,currentUserId=create_user}" property="xxxxListDtoList" ofType="com.cloud.datasynergy.model.xxxxListDto" javaType="java.util.ArrayList" select="selectXxxxXXXrenById"/>-->
        <collection autoMapping="true" column="{id=id,currentUserId=create_user}" javaType="ArrayList" ofType="xxx.xxx.xxx.xxx.实体类" property="实体类里面的list集合,用于存储子节点数据" select="selectXxxxXxxxrenById">
        </collection>
    </resultMap>


<select id="selectXxxxList" resultMap="xxxListTree">
        select * from t_Xxxx_list where parent_id = #{id} and create_user = #{currentUserId} and is_del = 0
    </select>


<select id="selectXxxxXXXrenById" resultMap="xxxListTree">
        select * from t_Xxxx_listwhere parent_id = #{id} and create_user = #{currentUserId} and is_del = 0
    </select>
  • 如何在递归是传递多个参数
column="{id=id,currentUserId=create_user}"
> =左边代表 dao or mapper 中的参数,=右边代表数据库表中的字段	
posted @ 2020-03-26 17:44  高方也  阅读(689)  评论(0编辑  收藏  举报