根据顶层的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));
}
相关推荐
许彰午4 小时前
14_Java泛型完全指南
java·windows·python
智慧物业老杨5 小时前
司法绿色通道下的物业纠纷数智化解决方案——基于“三优先“机制的全流程技术落地实践
java·django
2601_961194025 小时前
2026初级会计实务公式总结大全|计算题公式手册PDF
java·spring·eclipse·pdf·tomcat·hibernate
做个文艺程序员5 小时前
第1篇:K8s 核心概念精讲:Pod、Deployment、Service 与 Namespace——Java 开发者快速上手指南
java·云原生·容器·kubernetes·容器编排
小欣加油7 小时前
leetcode3751 范围内总波动值I
java·数据结构·c++·算法·leetcode
闪电悠米7 小时前
黑马点评-Redisson-01_why_redisson
java·服务器·网络·数据库·缓存·wpf
星轨zb7 小时前
LangChain4j 集成 Spring Boot:会话记忆 NPE 的根源与 ChatMemoryProvider 正确配置
java·spring boot·后端·langchain4j
JAVA9657 小时前
JAVA面试-并发篇 05-并发包AQS队列实现原理是什么
java·开发语言·面试
JAVA面经实录9177 小时前
RocketMQ全套学习知识手册
java·kafka·rabbitmq·rocketmq
phltxy8 小时前
Spring AI 从提示词到多模态
java·人工智能·spring