zoukankan      html  css  js  c++  java
  • 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整合spring+springMVC+Mybatis
    复杂系统分析与设计思路
    .NET数据挖掘与机器学习开源框架
    原来rollup这么简单之 rollup.watch篇
    面试官:说说你对css效率的理解
    两个实用的调试技巧
    Roma
    一个很实用的css技巧简析
    仅仅知道如何终止XHR请求,或许对你来说是不够的!
    再问你一遍,你真的了解try..catch(finally)吗???
  • 原文地址:https://www.cnblogs.com/yanzhen/p/12724999.html
Copyright © 2011-2022 走看看