/**
* list 数据
* t 当前节点(父节点)
*/privatestaticList<Map>getChildMapList(List<Map> list,Map t){List<Map> tlist =newArrayList<Map>();Iterator<Map> it = list.iterator();while(it.hasNext()){Map n =(Map) it.next();if(Integer.parseInt(n.get("parentId")+"")==Integer.parseInt(t.get("id")+"")){
tlist.add(n);}}return tlist;}
publicstaticvoidmain(String[] args){List<Map> list =menuList();System.out.println("-------平铺展示-------\n"+JSONUtil.toJsonStr(list));List<Map> mapList =buildMapTree(list);System.out.println("\n-------树形展示-------\n"+JSONUtil.toJsonStr(mapList));}-- run result
-------平铺展示-------[{"name":"系统设置","childList":[],"id":1,"parentId":0},{"name":"系统监控","childList":[],"id":2,"parentId":0},{"name":"用户管理","childList":[],"id":3,"parentId":1},{"name":"用户列表","childList":[],"id":4,"parentId":3}]-------树形展示-------[{"name":"系统设置","childList":[{"name":"用户管理","childList":[{"name":"用户列表","childList":[],"id":4,"parentId":3}],"id":3,"parentId":1}],"id":1,"parentId":0},{"name":"系统监控","childList":[],"id":2,"parentId":0}]