说明
代码是自己项目中的部分代码,对于小白可能不太友好,容易看不太懂,代码其实不是很重要,重要的是设计思路,比如我们做的java三大排序算法的时候,和打印菱形、五角星图案时候,只要自己明白的了设计思路,代码写起来就容易多了。
下面代码实现的思路还是,通过不断循环自身的方法,知道下级没有数据或者为null时,结局遍历循环。
树形结构数据中,根据父类id获取子孙后代id集合和 树形结构数据还原成普通list集合方法
/**
*
*获得下级子类id集合
* @return
*/
private void getChildrenIds(Long parentId,List<Long> idList) {
List<CustomEntityCategory> children= customCategoryService.list(Wrappers.<CustomEntityCategory>lambdaQuery().eq(CustomEntityCategory::getParentId,parentId));
if(CollectionUtil.isNotEmpty(children)){
idList.addAll(children.stream().map(CustomEntityCategory::getId).collect(Collectors.toList()));
children.forEach(e->{
getChil