根据顶层的id递归查询出全部子节点

效果图

根据输入的id为2查询出所有的红色框起来的节点

mapper接口

java 复制代码
TSystemOrg getOrgByorgId(String orgId);
List<TSystemOrg> getOrgListByParentId(String parentId);

mapper.xml

xml 复制代码
<!--根据id查询org-->
<select id="getOrgByorgId" resultType="com.iflytek.core.entity.TSystemOrg">
   SELECT
      *
   FROM
      t_system_org
   WHERE
      id=#{orgId}
   and
      is_delete = '0'
</select>

<!--根据parentId查询orgList-->
<select id="getOrgListByParentId" resultType="com.iflytek.core.entity.TSystemOrg">
   SELECT
      *
   FROM
      t_system_org
   WHERE
      parent_id=#{parentId}
   and
      is_delete = '0'
</select>

service接口

java 复制代码
List<TSystemOrg> getOrgListByOrgId(String orgId);

serviceImpl实现

java 复制代码
@Override
public List<TSystemOrg> getOrgListByOrgId(String orgId) {
    TSystemOrg org = mapper.getOrgByorgId(orgId);
    List<TSystemOrg> resultList = new ArrayList<>();
    resultList.add(org);
    diguiGetOrgListByParentId(org, resultList);
    return resultList;
}

private void diguiGetOrgListByParentId(TSystemOrg org, List<TSystemOrg> resultList) {
    List<TSystemOrg> orgList = mapper.getOrgListByParentId(org.getId());
    if(orgList != null){
        for(TSystemOrg o : orgList){
            resultList.add(o);
            //递归调用自己
            diguiGetOrgListByParentId(o,resultList);
        }
    }
}

controller

java 复制代码
@ApiOperation(value = "根据orgId获取所有子节点",tags = "机构")
@PostMapping("getOrgListByOrgId")
public ResultDto getOrgListByOrgId(String orgId){
    return ResultUtil.success("success", service.getOrgListByOrgId(orgId));
}
相关推荐
心流时间10 分钟前
[Java基础] JVM常量池介绍(BeanUtils.copyProperties(source, target)中的属性值引用的是同一个对象吗)
java·开发语言·jvm
瑞金彭于晏27 分钟前
通俗易懂版 Maven 科普,maven是什么?
java·maven
好看资源平台31 分钟前
Java Web开发实战与项目——Spring Boot与Spring Cloud微服务项目实战
java
.猫的树37 分钟前
Java集合List快速实现重复判断的10种方法深度解析
java·开发语言·list·集合
littlegirll1 小时前
命令行方式安装KFS同步KES到KADB
java·大数据·数据库
itachi-uchiha1 小时前
深入理解 Linux 中的 last 和 lastb 命令
java·linux·服务器
xiaoyustudiowww1 小时前
JSP + Servlet 实现 AJAX(纯JS版)
java·javascript·servlet
计算机毕设定制辅导-无忧学长1 小时前
Maven 插件的使用(一)
java·python·maven
一只_程序媛1 小时前
【leetcode hot 100 42】接雨水
java·算法·leetcode
代码小白%1 小时前
快速理解Spring 和 Spring Boot 的核心区别
java·spring boot·spring