//这是后台请求路径 @GetMapping("/getDept") public Wrapper getDept(){ //首先拿到全部数据 List<Map<String, Object>> deptList = deptService.getDeptAll(); //该集合用于接受第一个节点的数据 List<Map<String, Object>> mapList = new ArrayList<>(); //得到第一个接点的数据 for (int i = 0; i <deptList.size() ; i++) { if ((int)deptList.get(i).get("pid")<1){ mapList.add(deptList.get(i)); } } //调用getDe方法 getDe(mapList); return WrapMapper.ok(mapList); } public List<Map<String, Object>> getDe(List<Map<String, Object>> mapList){ //核心代码,递归调用 for (int i = 0; i <mapList.size() ; i++) { //如果该数据有子节点,则执行 if (deptService.getDept((int)mapList.get(i).get("id"))!=null){ List<Map<String, Object>> map = deptService.getDept((int)mapList.get(i).get("id")); mapList.get(i).put("children",map); getDe(map); } } return mapList; }
Java实现得到树形TreeGrid数据
最新推荐文章于 2021-02-23 23:23:04 发布