mybatis-plus树递归结构

java 复制代码
public interface MaterialCategoryMapper extends BaseMapper<MaterialCategory> {
    List<MaterialCategoryDto> queryAll(String code, String name, String operationName, String systemDeptId);

}
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="cn.microvideo.yingyun.jsxtzhdd.services.emergencysupplies.mapper.MaterialCategoryMapper">

    <resultMap id="nodeList"
               type="cn.microvideo.yingyun.jsxtzhdd.services.emergencysupplies.entity.MaterialCategoryDto">
        <id column="F_VC_ID" property="id"/>
        <result column="F_DT_DATA_CREATE_TIME" property="dataCreateTime"/>
        <result column="F_DT_DATA_UPDATE_TIME" property="dataUpdateTime"/>
        <result column="F_VC_MATERIAL_TYPE" property="materialType"/>
        <result column="F_VC_CODE" property="code"/>
        <result column="F_VC_NAME" property="name"/>
        <result column="F_VC_PARENT_ID" property="parentId"/>
        <result column="F_VC_OPERATION_ID" property="operationId"/>
        <result column="F_VC_OPERATION_NAME" property="operationName"/>
        <result column="F_INT_MATERIAL_NUM" property="materialNum"/>
        <result column="F_VC_SYSTEM_DEPT_ID" property="systemDeptId"/>
        <result column="F_VC_SYSTEM_DEPT_NAME" property="systemDeptName"/>
        <collection property="materialCategoryList"
                    select="getNodeByParentId" column="id=F_VC_ID"/>
    </resultMap>

    <select id="queryAll" resultMap="nodeList">
        select *
        from T_DF_MATERIAL_CATEGORY
        WHERE F_VC_PARENT_ID IS NULL
        <if test="code != null and code != ''">
            AND F_VC_CODE LIKE CONCAT( '%',#{code}, '%')
        </if>
        <if test="name != null and name != ''">
            AND F_VC_NAME LIKE CONCAT( '%',#{name}, '%')
        </if>
        <if test="operationName != null and operationName != ''">
            AND F_VC_OPERATION_NAME LIKE CONCAT( '%',#{operationName}, '%')
        </if>
        <if test="systemDeptId != null and systemDeptId != ''">
            AND F_VC_SYSTEM_DEPT_ID LIKE CONCAT(#{systemDeptId}, '%')
        </if>
        ORDER BY F_DT_DATA_CREATE_TIME DESC
    </select>

    <!-- 查询子节点,返回值类型应该使用正确的resultMap -->
    <select id="getNodeByParentId" resultMap="nodeList">
    select *
    from T_DF_MATERIAL_CATEGORY
    WHERE F_VC_PARENT_ID = #{id}
    ORDER BY F_DT_DATA_CREATE_TIME DESC
</select>

</mapper>
javascript 复制代码
package cn.microvideo.yingyun.jsxtzhdd.services.emergencysupplies.entity;

import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.Data;
import lombok.EqualsAndHashCode;

import java.time.LocalDateTime;
import java.util.List;

@Data
@EqualsAndHashCode(callSuper = false)
@TableName("T_DF_MATERIAL_CATEGORY")
public class MaterialCategoryDto {
    /**
     * 二级类目列表
     */
    @TableField(exist = false)
    List<MaterialCategoryDto> materialCategoryList;

    /**
     * 主键Id
     */
    @TableId(value = "F_VC_ID")
    private String id;

    /**
     * 数据创建时间
     */
    @TableField(value = "F_DT_DATA_CREATE_TIME")
    private LocalDateTime dataCreateTime;

    /**
     * 数据修改时间
     */
    @TableField(value = "F_DT_DATA_UPDATE_TIME")
    private LocalDateTime dataUpdateTime;

    /**
     * 物资类型
     */
    @TableField("F_VC_MATERIAL_TYPE")
    private String materialType;

    /**
     * 编码
     */
    @TableField("F_VC_CODE")
    private String code;

    /**
     * 名称
     */
    @TableField("F_VC_NAME")
    private String name;

    /**
     * 父级id
     */
    @TableField("F_VC_PARENT_ID")
    private String parentId;

    /**
     * 用户id
     */
    @TableField("F_VC_OPERATION_ID")
    private String operationId;

    /**
     * 用户名称
     */
    @TableField("F_VC_OPERATION_NAME")
    private String operationName;

    /**
     * 挂靠物资数量
     */
    @TableField("F_INT_MATERIAL_NUM")
    private Integer materialNum;

    /**
     * 单位id
     */
    @TableField(value = "F_VC_SYSTEM_DEPT_ID")
    private String systemDeptId;

    /**
     * 单位名称
     */
    @TableField(value = "F_VC_SYSTEM_DEPT_NAME")
    private String systemDeptName;

    /**
     * 1:一级类目;2:二级类目
     */
    private Integer grade;
}
相关推荐
roman_日积跬步-终至千里6 分钟前
【Java并发】多线程/并发问题集
java·开发语言
调皮连续波(rsp_tiaopige)9 分钟前
毫米波雷达 : OpenRadar(Matlab版本)正式发布
开发语言·matlab
冷雨夜中漫步20 分钟前
python反转列表reverse()和[::-1]哪个效率更高
开发语言·python
rainbow688923 分钟前
Python面向对象编程与异常处理实战
开发语言·python
それども26 分钟前
什么是MalformedStreamException,和WebKitFormBoundary有什么关系
java
你撅嘴真丑1 小时前
第八章 - 贪心法
开发语言·c++·算法
思想在飞肢体在追1 小时前
Springboot项目配置Nacos
java·spring boot·后端·nacos
cyforkk1 小时前
09、Java 基础硬核复习:异常处理(容错机制)的核心逻辑与面试考点
java·数据库·面试
梵刹古音1 小时前
【C语言】 浮点型(实型)变量
c语言·开发语言·嵌入式
历程里程碑1 小时前
Linux 17 程序地址空间
linux·运维·服务器·开发语言·数据结构·笔记·排序算法