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;
}
相关推荐
傻乐u兔6 小时前
C语言进阶————指针4
c语言·开发语言
大模型玩家七七6 小时前
基于语义切分 vs 基于结构切分的实际差异
java·开发语言·数据库·安全·batch
历程里程碑6 小时前
Linux22 文件系统
linux·运维·c语言·开发语言·数据结构·c++·算法
牛奔7 小时前
Go 如何避免频繁抢占?
开发语言·后端·golang
寻星探路11 小时前
【深度长文】万字攻克网络原理:从 HTTP 报文解构到 HTTPS 终极加密逻辑
java·开发语言·网络·python·http·ai·https
lly20240612 小时前
Bootstrap 警告框
开发语言
2601_9491465313 小时前
C语言语音通知接口接入教程:如何使用C语言直接调用语音预警API
c语言·开发语言
曹牧13 小时前
Spring Boot:如何测试Java Controller中的POST请求?
java·开发语言
KYGALYX13 小时前
服务异步通信
开发语言·后端·微服务·ruby