本文主要是介绍mybatis 实现递归查询出树结构节点,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
mybatis 实现递归查询出树结构节点
<?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.modules.guide.mapper.BookDirectoryDao"><resultMap id="directoryVoMap" type="com.modules.guide.vo.BookDirectoryVo"><id column="id" jdbcType="VARCHAR" property="id" /><result column="book_id" jdbcType="VARCHAR" property="bookId" /><result column="directory_name" jdbcType="VARCHAR" property="directoryName" /><result column="page_num" jdbcType="INTEGER" property="pageNum" /><result column="grade" jdbcType="INTEGER" property="grade" /><result column="parent_id" jdbcType="VARCHAR" property="parentId" /><result column="del_flag" jdbcType="INTEGER" property="delFlag" /><result column="create_by" jdbcType="VARCHAR" property="createBy" /><result column="create_date" jdbcType="TIMESTAMP" property="createDate" /><collection property="children" column="{id=id,grade=grade}" ofType="map" javaType="java.util.List" select="getChildrenList" ></collection></resultMap><resultMap id="nextDirectoryVoMap" type="com.modules.guide.vo.BookDirectoryVo"><id column="id" jdbcType="VARCHAR" property="id" /><result column="book_id" jdbcType="VARCHAR" property="bookId" /><result column="directory_name" jdbcType="VARCHAR" property="directoryName" /><result column="page_num" jdbcType="INTEGER" property="pageNum" /><result column="grade" jdbcType="INTEGER" property="grade" /><result column="parent_id" jdbcType="VARCHAR" property="parentId" /><result column="del_flag" jdbcType="INTEGER" property="delFlag" /><result column="create_by" jdbcType="VARCHAR" property="createBy" /><result column="create_date" jdbcType="TIMESTAMP" property="createDate" /><collection property="children" column="{id=id,grade=grade}" ofType="map" javaType="java.util.List" select="getChildrenList" ></collection></resultMap><select id="query" parameterType="java.util.Map" resultType="BookDirectory">select * from t_guide_book_directory where 1=1<if test="id!=null and id!=''">and id=#{id}</if><if test="queryparam!=null and queryparam!=''">${queryparam}</if>order by page_num asc
</select><!-- 电子书目录列表查询 -->
<select id="getBookDirectoryVo" parameterType="com.modules.guide.entity.BookDirectory" resultMap="nextDirectoryVoMap">select * from t_guide_book_directory where book_id = #{bookId,jdbcType=VARCHAR} and parent_id LIKE CONCAT('%',#{parentId,jdbcType=VARCHAR} ,'%') and grade = #{grade,jdbcType=INTEGER}order by page_num asc
</select><!-- 电子书子目录 -->
<select id="getChildrenList" parameterType="java.util.Map" resultMap="directoryVoMap">select * from t_guide_book_directory where parent_id LIKE CONCAT('%',CONCAT(#{id,jdbcType=VARCHAR},"_",#{grade,jdbcType=VARCHAR}) ,'%') and grade = (#{grade,jdbcType=INTEGER} + 1)order by page_num asc
</select></mapper>
这篇关于mybatis 实现递归查询出树结构节点的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!