// 计算所有节点的level public static List<Map<String, Object>> caculateLevel( List<Map<String, Object>> list) { //从所有节点中,找出所有的顶级节点 List<Map<String, Object>> topLevelList = TreeMenuUtil.findTopLevelNodeList(list); //遍历顶级节点 for (Map<String, Object> top : topLevelList) { //顶级节点的level为1 level = 1; top.put("level", level); //为每一个顶级节点,构造子结点树 child(list, top); } return list; } //为当前节点,构造子结点,再构造子结点的子结点 private static void child(List<Map<String, Object>> list, Map<String, Object> parent) { //找出一个节点的所有一级子结点 List<Map<String, Object>> childList = TreeMenuUtil.findAllChild(parent, list); //遍历子结点 for (Map<String, Object> child : childList) { //深度+1 level++; child.put("level", level); child(list, child); //回退,深度-1 level--; } }原文首发:http://fansunion.cn/article/detail/573.html
简洁常用权限系统的设计与实现(五):不维护节点的深度level,手动计算level,构造树
原文地址:http://blog.csdn.net/fansunion/article/details/42057167