1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37
| public List<Map<String, Object>> getRootDict() { List<Map<String, Object>> returnList = new ArrayList<>(); List<Map<String, Object>> dictList = dictMapper.getAllDict(); Map<String, Object> map = new HashMap<>(16); map.put("name", "数据字典"); map.put("id", null); map.put("pid", null);
List<Map<String, Object>> rootTree = this.rebuildRootTree("0",dictList); map.put("child", rootTree); returnList.add(map); return returnList; }
List<Map<String, Object>> rebuildRootTree(String pid ,List<Map<String, Object>> dictList){ List<Map<String, Object>> rootTree = new ArrayList<>(); for(Map<String, Object> dictMap:dictList){ if(dictMap.containsKey("pid") && Objects.equals(dictMap.get("pid").toString(),pid)) { Map<String, Object> newMap = new HashMap<>(16); newMap.put("name", dictMap.get("name")); newMap.put("id", dictMap.get("id")); newMap.put("pid", dictMap.get("pid")); newMap.put("child",this.rebuildRootTree((dictMap.get("id")).toString(),dictList)); rootTree.add(newMap); } } return rootTree; }
|