当前位置:网站首页>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;
}
边栏推荐
- WebSocket Session为null
- 11. Redis implements follow, unfollow, and follow and follower lists
- 【编译原理】递归下降语法分析设计原理与实现
- 【CocosCreator 3.5】CocosCreator 获取网络状态
- Map.Entry理解和应用
- Chapter 9 SVM Practice
- Modbus on AT32 MCUs
- What is distributed and clustered?What is the difference?
- 【异常】The field file exceeds its maximum permitted size of 1048576 bytes.
- 5. SAP ABAP OData 服务如何支持 $filter (过滤)操作
猜你喜欢
接口测试关键技术
Mycat's master-slave relationship, vertical sub-database, horizontal sub-table, and detailed configuration of mycat fragmented table query (mysql5.7 series)
华为分布式存储FusionStorage知识点总结【面试篇】
SQL注入 Less46(order by后的注入+rand()布尔盲注)
19. Support Vector Machines - Intuitive Understanding of Optimization Objectives and Large Spacing
【C语言】求两个整数m和n的最大公因数和最小公倍数之和一般方法,经典解法
The whole process scheduling, MySQL and Sqoop
Software accumulation -- Screenshot software ScreenToGif
TCP详解(一)
Why is String immutable?
随机推荐
LeetCode中等题之分数加减运算
10、Redis实现点赞(Set)和获取总点赞数
原子操作 CAS
execsnoop 工具
11、Redis实现关注、取消关注以及关注和粉丝列表
图解lower_bound&upper_bound
学习DAVID数据库(1)
JetPack组件Databinding
选好冒烟测试用例,为进入QA的制品包把好第一道关
Clustering index, and what is the difference between a clustering index
2022牛客多校联赛第四场 题解
Getting Started with CefSharp - winform
mycat的主从关系 垂直分库 水平分表 以及mycat分片联表查询的配置详解(mysql5.7系列)
The difference between link and @import
STM32问题合集
WebSocket Session为null
SQL注入 Less46(order by后的注入+rand()布尔盲注)
【C语言】求两个整数m和n的最大公因数和最小公倍数之和一般方法,经典解法
Discussion on Service Commitment of Class Objects under Multithreading
YOLOV5 study notes (2) - environment installation + operation + training