public List<CatalogueAndPage> getAllCatalogueAndPage(String account){
List<CatalogueAndPage> catalogueAndPageTreeList = new ArrayList<>();
List<SysMenu> allSysAdminDISTINCTMenu = sysMenuRepository.findAllSysAdminDISTINCTMenu(account);
for (SysMenu sysMenu:allSysAdminDISTINCTMenu) {
if(Objects.isNull(sysMenu.getParentId())){
CatalogueAndPage catalogueAndPage = new CatalogueAndPage();
BeanUtils.copyProperties(sysMenu,catalogueAndPage);
// catalogueAndPage.setId(sysMenu.getId());
catalogueAndPageTreeList.add(catalogueAndPage);
}else{
//是不是儿子递归
getChildren(catalogueAndPageTreeList,sysMenu);
}
}
return catalogueAndPageTreeList;
}
public void getChildren(List<CatalogueAndPage> catalogueAndPageTreeList ,SysMenu sysMenu){
for (CatalogueAndPage node:catalogueAndPageTreeList) {
if(node.getChildList() == null){
node.setChildList(new ArrayList<>());
}
if(sysMenu.getParentId().equals(node.getId())){
//是不是顶级的儿子
CatalogueAndPage catalogueAndPage = new CatalogueAndPage();
BeanUtils.copyProperties(sysMenu,catalogueAndPage);
node.getChildList().add(catalogueAndPage);
}else if(node.getChildList().size() > 0){
//是不是顶级儿子的儿子
getChildren(node.getChildList(), sysMenu);
}
}
}
标签:node,CatalogueAndPage,catalogueAndPageTreeList,父级,生成,id,new,catalogueAndPage,sys
From: https://www.cnblogs.com/Arborblog/p/16780313.html