使用递归的方法设置节点
private List
<CatalogNode> buildChildrenList(List
<CatalogNode> catalogList
) {
List
<CatalogNode> nodeList
= catalogList
.stream().filter(catalogNode
-> StringUtils
.isBlank(catalogNode
.getPid()))
.map(catalogNode
-> {
catalogNode
.setChildren(getChildren(catalogNode
, catalogList
));
return catalogNode
;
})
.collect(Collectors
.toList());
return nodeList
;
}
private List
<CatalogNode> getChildren(CatalogNode root
, List
<CatalogNode> all
) {
List
<CatalogNode> children
= all
.stream().filter(catalogNode
-> {
if(StringUtils
.isNotBlank(catalogNode
.getPid())) {
catalogNode
.setAttributes(new Attribute("seq", catalogNode
.getCatalogSeq()));
return catalogNode
.getPid().equals(root
.getId());
}
return false;
}
).map((menu
) -> {
menu
.setChildren(getChildren(menu
, all
));
return menu
;
}).collect(Collectors
.toList());
return children
;
}
转载请注明原文地址: https://lol.8miu.com/read-27823.html