递归目录方法

sourcelist是先把所有的资源都放在这个列表里面

先根据用户把所属的根menu拿出来放在rootmenu里面,作为参数传给treeroot方法

/**
* 递归获取菜单
* treeRoot:( ). <br/>
* @author lishang
* @param sourceList
* @param rootMenu
* @return
*/
public static Menu treeRoot(List<Menu> sourceList,Menu rootMenu)
{
if (sourceList == null)
{
return null;
}
List<Menu> childList=new ArrayList<>();
for (Menu menu : sourceList) {
if(rootMenu.getId().equals(menu.getParentId())){
Menu menuChild = treeRoot(sourceList, menu);
childList.add(menuChild);
}
}
if(childList.size()==0){
return rootMenu;
}
rootMenu.setChildrens(childList);
return rootMenu;
}

原文地址:https://www.cnblogs.com/handsome1013/p/10441138.html