1、
/*建立树形结构*/
public List<Department> builTree(){
List<Department> treeMenus =new ArrayList<Department>();
for(Department menuNode : getRootNode()) {
menuNode=buildChilTree(menuNode);
treeMenus.add(menuNode);
}
return treeMenus;
}
/*递归,建立子树形结构*/
private Department buildChilTree(Department pNode){
List<Department> chilMenus =new ArrayList<Department>();
for(Department menuNode : menuList) {
if(menuNode.getParentId().equals(pNode.getId())) {
chilMenus.add(buildChilTree(menuNode));
}
}
pNode.setChildren(chilMenus);
return pNode;
}
/*获取根节点*/
private List<Department> getRootNode() {
List<Department> rootMenuLists =new ArrayList<Department>();
for(Department menuNode : menuList) {
if(menuNode.getParentId().equals("1")) {
rootMenuLists.add(menuNode);
}
}
return rootMenuLists;
}
builTree();
2、
/*建立全部树形结构*/
List<FuncConfig> buildChilTree(String parentId){
List<FuncConfig> list = funcConfigMapper.getFuncParentId(parentId);
for(FuncConfig funcConfigVo : list) {
String id = funcConfigVo.getId();
List<FuncConfig> child = buildChilTree(id);
if(!child.isEmpty()) {
funcConfigVo.setChildren(child);
}
}
return list;
}