当前位置:网站首页>Recursive query single table - single table tree structure - (self-use)
Recursive query single table - single table tree structure - (self-use)
2022-07-31 03:03:00 【Gerald Peake Shea】
Recursively query a single table
Single table recursive application scenario,The tree structure sinks infinitely(如下图)

表结构 parent_id(父亲id)

实体类
@Data
@Builder
@AllArgsConstructor
@NoArgsConstructor
@TableName(value = "t_dept")
public class OrgDept implements Serializable {
/** * 组织架构 */
@TableId(value = "org_id", type = IdType.INPUT)
private Long orgId;
/** * 组织code */
@TableField(value = "org_code")
private String orgCode;
/** * 组织名称 */
@TableField(value = "org_name")
private String orgName;
/** * 父节点 */
@TableField(value = "parent_id")
private Long parentId;
/** * 组织描述 */
@TableField(value = "org_address")
private String orgAddress;
/** * 创建时间 */
@TableField(value = "create_time")
private Date createTime;
/** * 创建人 */
@TableField(value = "create_by")
private String createBy;
/** * 电话号码 */
@TableField(value = "phone_number")
private String phoneNumber;
/** * 排序 */
@TableField(value = "order_number")
private Integer orderNumber;
@TableField(exist = false)
private String parentName;
@TableField(exist = false)
List<OrgDept> children;
/** * 部门id集合 */
@TableField(exist = false)
List<Integer> depaIds;
private static final long serialVersionUID = 1L;
}
impl 递归开始
listRoleOrgDept
@Override
@Transactional(rollbackFor = Exception.class)
public List<OrgDept> listRoleOrgDept(Long deptId) {
//
List<Long> depaIds = new ArrayList<>();
// x_1 Department full list
List<OrgDept> orgDepts = new LambdaQueryChainWrapper<>(orgDeptMapper)
.list();
//Defines the return object child parent nesting
List<OrgDept> parentMenu;
// When the page is clicked, the current node will be captured to get the nodeid If not default all
if (deptId == null) {
// 获取全部列表
parentMenu = orgDepts.stream().filter(e -> e.getParentId().equals(0L)).collect(Collectors.toList());
//
for (OrgDept sysMenu : parentMenu) {
depaIds.add(sysMenu.getOrgId());
setChild(sysMenu, orgDepts, depaIds);
}
} else {
parentMenu = pIdLive(deptId, orgDepts, depaIds);
}
return parentMenu;
}
边栏推荐
- What is SQALE
- Crypto Firms Offer Offer To Theft Hackers: Keep A Little, Give The Rest
- 7. List of private messages
- 什么是分布式锁?实现分布式锁的三种方式
- 8. Unified exception handling (controller notifies @ControllerAdvice global configuration class, @ExceptionHandler handles exceptions uniformly)
- 12 磁盘相关命令
- 跨专业考研难度大?“上岸”成功率低?这份实用攻略请收下!
- 解析小结—自用
- The modification is not properly placed in the sandbox, causing Apple compatibility issues
- SonarQube的BUG定义
猜你喜欢

YOLOV5学习笔记(二)——环境安装+运行+训练

Moxa NPort 设备缺陷可能使关键基础设施遭受破坏性攻击

LeetCode简单题之两个数组间的距离值

The simulation application of common mode inductance is here, full of dry goods for everyone

Discourse Custom Header Links

12 磁盘相关命令

Why is String immutable?

华为分布式存储FusionStorage知识点总结【面试篇】

Local area network computer hardware information collection tool

【C语言】进制转换一般方法
随机推荐
JS function this context runtime syntax parentheses array IIFE timer delay self.backup context call apply
YOLOV5 study notes (2) - environment installation + operation + training
关于 mysql8.0数据库中主键位id,使用replace插入id为0时,实际id插入后自增导致数据重复插入 的解决方法
StringJoiner in detail
6. Display comments and replies
Office automation case: how to automatically generate period data?
跨专业考研难度大?“上岸”成功率低?这份实用攻略请收下!
SQL注入 Less54(限制次数的SQL注入+union注入)
IIR滤波器和FIR滤波器
16、热帖排行
YOLOV5学习笔记(三)——网络模块详解
CentOS7下mysql5.7.37的安装【完美方案】
12 Disk related commands
共模电感的仿真应用来了,满满的干货送给大家
如何搭建私有yum源
10 权限介绍
SQL injection Less54 (limited number of SQL injection + union injection)
学习DAVID数据库(1)
Software accumulation -- Screenshot software ScreenToGif
Discourse Custom Header Links