-- 查询出该组织下所有组织id的集合 --方法一: public List<Integer> getAllOrgid1(List<Integer> orgid,List<Integer> list,Boolean isIncludeSelf){ list.addAll(orgid); List<Integer> intList=new ArrayList<Integer>(); for(Integer i : orgid){ List<Org> orglist = orgService.selectInfo(" FROM Org Where 1=1 and parentId="+i); for(Org o : orglist){ intList.add(o.getOrgid()); } } if(intList.size()>0){ return getAllOrgid1(intList,list,isIncludeSelf); } return list; } --方法二: public String getAllOrgids(Integer orgid){ String allOrgId=getAllOrgid(orgid,""); if("".equals(allOrgId)){ return orgid.toString(); }else{ allOrgId+=","+orgid; return allOrgId; } } public String getAllOrgid(Integer orgid,String str){ List<Org> orglist = orgService.selectInfo(" FROM Org "); if(orglist!=null&&orglist.size()>0){ int index = 0; for(Org o : orglist){ String parentId1=o.getParentId().toString(); String orgidNow1=orgid.toString(); if(parentId1.equals(orgidNow1)){ if(index > 0){ str += ","; index = 0; } str+=o.getOrgid(); boolean bool = false; for(int j=0; j< orglist.size(); j++){ String parentId2=orglist.get(j).getParentId().toString(); String orgidNow2=o.getOrgid().toString(); if(parentId2.equals(orgidNow2)){ bool = true; break; } } if(bool){ // 调用自身,实现递归 str += ","; str = getAllOrgid(o.getOrgid(),str); } index ++; } } } return str; }