Java SE 之 递归方法
1 public void removeSon(String id, List<Dept> deptList) { 2 String hql = "from Dept where parent.id = ?"; 3 List<Dept> list = baseDao.find(hql, Dept.class,new Object[]{id}); 4 if(list!=null && list.size()>0){ 5 for (Dept d:list) { 6 removeSon(d.getId(),deptList); 7 } 8 } 9 Dept dept = baseDao.get(Dept.class, id); 10 deptList.remove(dept); 11 }
思路:
1 本部门有n个子部门 2 每个子部门下还有n个子部门 3 4 删除 5 思路:FUNCTION判断我下面是否还有子部门(ID) 6 有 7 获取他们 8 n个子部门 9 FUNCTION判断我下面是否还有子部门(id) 10 没有 11 删除自己
注意事项:递归不可以有返回值