当前位置:网站首页>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;
}
边栏推荐
- Maximum area of solar panel od js
- Graphical lower_bound & upper_bound
- 5. SAP ABAP OData 服务如何支持 $filter (过滤)操作
- Discourse Custom Header Links
- 学习DAVID数据库(1)
- 观察者模式
- 加密公司向盗窃的黑客提供报价:保留一点,把剩下的归还
- mycat的主从关系 垂直分库 水平分表 以及mycat分片联表查询的配置详解(mysql5.7系列)
- 10. Redis implements likes (Set) and obtains the total number of likes
- JS function this context runtime syntax parentheses array IIFE timer delay self.backup context call apply
猜你喜欢
【Android】Room —— SQLite的替代品
The use of font compression artifact font-spider
StringJoiner in detail
什么是系统?
The simulation application of common mode inductance is here, full of dry goods for everyone
Getting Started with CefSharp - winform
Discourse 自定义头部链接(Custom Header Links)
SQL注入 Less46(order by后的注入+rand()布尔盲注)
【C语言】表达式求值的一般方法
什么是分布式锁?实现分布式锁的三种方式
随机推荐
Chapter 9 SVM实践
原子操作 CAS
10、Redis实现点赞(Set)和获取总点赞数
Getting Started with CefSharp - winform
STM32问题合集
分布式系统架构需要解决的问题
CefSharp入门-winform
What is a distributed lock?Three ways of implementing distributed lock
MultipartFile文件上传
Basic learning about Redis related content
Maximum area of solar panel od js
字体压缩神器font-spider的使用
【C语言】三子棋(经典解法+一览图)
mycat的主从关系 垂直分库 水平分表 以及mycat分片联表查询的配置详解(mysql5.7系列)
分布式与集群是什么 ? 区别是什么?
SQL injection Less54 (limited number of SQL injection + union injection)
php 网站的多语言设置(IP地址区分国内国外)
如何搭建私有yum源
Addition and Subtraction of Scores in LeetCode Medium Questions
跨专业考研难度大?“上岸”成功率低?这份实用攻略请收下!