• SprintBoot Mapper 树形查询


    SprintBoot Mapper 树形查询

    DeptMapper.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="com.zhen.mp.mapper.DeptMapper">
        <resultMap id="treeMap" type="com.zhen.mp.dto.dept.DeptTreeDto">
            <id column="id" property="id"/>
            <result column="p_id" property="ppId" />
            <result column="name" property="name" />
            <result column="sort" property="sort" />
            <collection column="id" property="sonNode" javaType="java.util.ArrayList"  ofType="com.zhen.mp.dto.dept.DeptTreeDto" select="getNextTree"/>
        </resultMap>
        <select id="getTree" resultMap="treeMap">
            select * from dept where p_id is null;
        </select>
        <select id="getNextTree" resultMap="treeMap">
            select * from dept where p_id = #{id}
        </select>
    </mapper>
    

    DeptMapper.java

    package com.zhen.mp.mapper;
    import com.baomidou.mybatisplus.core.mapper.BaseMapper;
    import com.zhen.mp.bean.Dept;
    import com.zhen.mp.dto.dept.DeptTreeDto;
    import org.springframework.stereotype.Repository;
    import java.util.List;
    @Repository
    public interface DeptMapper extends BaseMapper<Dept> {
        List<DeptTreeDto> getTree();
        List<DeptTreeDto> getNextTree();
    }
    

    Dept.java

    package com.zhen.mp.bean;
    import com.baomidou.mybatisplus.annotation.IdType;
    import com.baomidou.mybatisplus.annotation.TableId;
    import com.baomidou.mybatisplus.annotation.TableName;
    import com.baomidou.mybatisplus.extension.activerecord.Model;
    import lombok.Data;
    @Data
    @TableName("dept")
    public class Dept extends Model {
        @TableId(type = IdType.AUTO)
        private Long id;
        private Long pId;
        private String name;
        private Integer sort;
    }
    

    DeptTreeDto.java

    package com.zhen.mp.dto.dept;
    import lombok.Data;
    import java.util.List;
    @Data
    public class DeptTreeDto {
        private Long id;
        private Long ppId;
        private String name;
        private Integer sort;
        private List<DeptTreeDto> sonNode;
    }
    
    
  • 相关阅读:
    Eclipse导入Ant项目
    Eclipse修改默认包路径的起始文件夹
    Java中DAO/DTO/PO/VO/BO/QO/POJO
    FreeMarker与Spring MVC 4集合的HelloWorld示例
    FreeMarker与Spring MVC 4结合错误:Caused by: java.lang.NoClassDefFoundError: org/springframework/ui/freemarker/FreeMarkerConfiguration
    FreeMarker与Servlet结合示例
    FreeMarker-简单示例
    Java模板引擎-FreeMarker
    SiteMesh2-sitemesh.xml的其它映射器的用法
    SiteMesh2-sitemesh.xml的ParameterDecoratorMapper映射器的用法
  • 原文地址:https://www.cnblogs.com/yanzhen/p/12724999.html
Copyright © 2020-2023  润新知