当前位置:网站首页>递归查询单表-单表树结构-(自用)
递归查询单表-单表树结构-(自用)
2022-07-31 03:00:00 【杰拉德·皮克·谢】
单表递归应用场景,树结构无限下沉(如下图)

表结构 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 部门全部列表
List<OrgDept> orgDepts = new LambdaQueryChainWrapper<>(orgDeptMapper)
.list();
//定义返回对象子父嵌套
List<OrgDept> parentMenu;
// 点击页面时会捕捉当前节点拿到节点id 如果没有默认全部
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;
}
边栏推荐
- LeetCode简单题之找到和最大的长度为 K 的子序列
- Go 项目实战-获取多级分类下的全部商品
- JetPack组件Databinding
- Discussion on Service Commitment of Class Objects under Multithreading
- 5. SAP ABAP OData 服务如何支持 $filter (过滤)操作
- 公司官网建站笔记(六):域名进行公安备案并将备案号显示在网页底部
- 数学解决——环形链表问题
- SQL注入 Less54(限制次数的SQL注入+union注入)
- 【shell基础】判断目录是否为空
- 【Bank Series Phase 1】People's Bank of China
猜你喜欢

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

Mycat's master-slave relationship, vertical sub-database, horizontal sub-table, and detailed configuration of mycat fragmented table query (mysql5.7 series)

Basic learning about Redis related content

CorelDRAW2022 streamlined Asia Pacific new features in detail

QML的使用
![Installation of mysql5.7.37 under CentOS7 [perfect solution]](/img/ef/a89d8bfd09377dc30034bad99dfd07.png)
Installation of mysql5.7.37 under CentOS7 [perfect solution]

你们程序员为什么不靠自己的项目谋生?而必须为其他人打工?

【C语言】三子棋(经典解法+一览图)

品牌广告投放平台的中台化应用与实践

What is distributed and clustered?What is the difference?
随机推荐
10. Redis implements likes (Set) and obtains the total number of likes
SQL injection Less46 (injection after order by + rand() Boolean blind injection)
【编译原理】递归下降语法分析设计原理与实现
The simulation application of common mode inductance is here, full of dry goods for everyone
QML的使用
2022牛客多校联赛第四场 题解
JetPack component Databinding
Huawei od dice js
冒泡排序、选择排序、直接插入排序、二分法查找
SQL注入 Less54(限制次数的SQL注入+union注入)
Modbus on AT32 MCUs
Local area network computer hardware information collection tool
SQALE 是什么
Mysql 45讲学习笔记(二十五)MYSQL保证高可用
BAT can't sell "Medical Cloud": Hospitals flee, mountains stand, and there are rules
知识蒸馏7:知识蒸馏代码详解
try-catch中含return
CorelDRAW2022精简亚太新增功能详细介绍
Unity3D Button 鼠标悬浮进入与鼠标悬浮退出按钮事件
Word/Excel fixed table size, when filling in the content, the table does not change with the cell content