当前位置:网站首页>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;
}
边栏推荐
猜你喜欢
Mathematics to solve the problem - circular linked list
一份高质量的测试用例如何养成?
QML的使用
跨专业考研难度大?“上岸”成功率低?这份实用攻略请收下!
YOLOV5 study notes (3) - detailed explanation of network module
Installation of mysql5.7.37 under CentOS7 [perfect solution]
Mysql 45讲学习笔记(二十四)MYSQL主从一致
Basic learning about Redis related content
局域网电脑硬件信息收集工具
【C语言】表达式求值的一般方法
随机推荐
7、私信列表
遗留系统的自动化策略
【Cocos Creator 3.5】缓动系统停止所有动画
学习DAVID数据库(1)
原子操作 CAS
CentOS7下mysql5.7.37的卸载【完美方案】
15. Website Statistics
CorelDRAW2022精简亚太新增功能详细介绍
解析小结—自用
Mycat's master-slave relationship, vertical sub-database, horizontal sub-table, and detailed configuration of mycat fragmented table query (mysql5.7 series)
Getting Started with CefSharp - winform
你们程序员为什么不靠自己的项目谋生?而必须为其他人打工?
Is interprofessional examination difficult?Low success rate of "going ashore"?Please accept this practical guide!
Number 16, top posts
6. Display comments and replies
YOLOV5 study notes (3) - detailed explanation of network module
QML的使用
f.grid_sample
CentOS7下mysql5.7.37的安装【完美方案】
【C语言】预处理操作