当前位置:网站首页>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;
}
边栏推荐
- 华为分布式存储FusionStorage知识点总结【面试篇】
- SQL injection Less54 (limited number of SQL injection + union injection)
- 局域网电脑硬件信息收集工具
- SonarQube的BUG定义
- CorelDRAW2022精简亚太新增功能详细介绍
- 刚出道“一战成名”,安全、舒适一个不落
- TCP详解(一)
- Classic linked list OJ strong training problem - fast and slow double pointer efficient solution
- Thesis framework of the opening report
- 10、Redis实现点赞(Set)和获取总点赞数
猜你喜欢

Project (5) - Small target detection tph-yolov5

Word/Excel fixed table size, when filling in the content, the table does not change with the cell content

SQL injection Less54 (limited number of SQL injection + union injection)

Pythagorean tuple od js

SQL注入 Less46(order by后的注入+rand()布尔盲注)

7、私信列表

mycat的主从关系 垂直分库 水平分表 以及mycat分片联表查询的配置详解(mysql5.7系列)

11、Redis实现关注、取消关注以及关注和粉丝列表

C#远程调试

LeetCode简单题之找到和最大的长度为 K 的子序列
随机推荐
TCP详解(二)
JetPack组件Databinding
多线程下类对象的服务承诺探讨
Discourse Custom Header Links
2022牛客多校联赛第四场 题解
php 网站的多语言设置(IP地址区分国内国外)
什么是系统?
MultipartFile file upload
YOLOV5学习笔记(二)——环境安装+运行+训练
Why is String immutable?
Compile Hudi
局域网电脑硬件信息收集工具
YOLOV5学习笔记(三)——网络模块详解
Classic linked list OJ strong training problem - fast and slow double pointer efficient solution
什么是分布式锁?实现分布式锁的三种方式
观察者模式
Mysql 45讲学习笔记(二十四)MYSQL主从一致
The simulation application of common mode inductance is here, full of dry goods for everyone
IDEA 注释报红解决
【C语言】表达式求值的一般方法