public void getTree() { String parentId="0"; Map<String, Object> map = new HashMap<>(); try { Department province = deptService.selectDeptMentByParentId(parentId).get(0);; //查询出一个部门 List<Personnel> personnelList= personnelServer.selectByDeptId(province.getDepartmentId().toString()); //查询部门下的人员 province.put("personnelMap",personnelList); if (province != null) { List<Department> citys = deptService.selectDeptMentByParentId(province.getDepartmentId().toString());//查询省下面的所有市 digui(citys); //调用递归算法查询市以下的区县 // province.setChildren(citys); province.put("childer",citys); } map.put("data", province); } catch (Exception e) { e.printStackTrace(); } renderJson(new Record().set("result", 1).set("data",map)); } public void digui(List<Department> citys) { List<Department> retList = new ArrayList<>(); for (Department c : citys) { retList = deptService.selectDeptMentByParentId(c.getDepartmentId().toString()); List<Personnel> personnelList= personnelServer.selectByDeptId(c.getDepartmentId().toString()); //查询部门下的人员 c.put("personnelMap",personnelList); if (retList.size() > 0) { c.put("childer",retList); digui(retList); //循环调用自己 } } }
递归的组织树的格式
最新推荐文章于 2024-05-16 23:28:15 发布