日期:2014-05-20 浏览次数:20633 次
//查找下级机构的递归 List<Sysjgxxb> jgxxList3 = new ArrayList<Sysjgxxb>(); public List<Sysjgxxb> findXjjg(List<Sysjgxxb> jgxxList) { String jgxxSql = null; List<Sysjgxxb> jgxxList1 = new ArrayList<Sysjgxxb>(); List<Sysjgxxb> jgxxList2 = new ArrayList<Sysjgxxb>(); try { for (int jgxxi=0; jgxxi<jgxxList.size(); jgxxi++) { //设置SQL语句 jgxxSql = "SELECT jgxx FROM Sysjgxxb jgxx WHERE jgxx.上级机构 = '" + jgxxList.get(jgxxi).机构码() + "' AND jgxx.机构码 != '" + jgxxList.get(jgxxi).机构码() + "'"; jgxxList1 = 按照SQL语句查询出符合条件的机构信息; if (jgxxList1 != null && jgxxList.size() > 0) { for ( int jgxxj=0; jgxxj<jgxxList1.size(); jgxxj++) { jgxxList2.add(jgxxList1.get(jgxxj)); } for ( int jgxxk=0; jgxxk<jgxxList2.size(); jgxxk++) { jgxxList3.add(jgxxList2.get(jgxxk)); } } else if (jgxxList1 == null && jgxxList2.isEmpty()) { continue; } } if(jgxxList2 != null && jgxxList2.size() > 0) { findXjjg(jgxxList2); } } catch (Exception e) { e.printStackTrace(); } if (jgxxList3 != null && jgxxList3.size() > 0) { return jgxxList3; } return null; }
//这是调用那个递归最后返回到页面的方法 sysjgxxbList = 这是一个需要得到下机机构码的机构信息 List<Sysjgxxb> resultList = findXjjg(sysjgxxbList); if(resultList != null && resultList.size() > 0) { for ( int i=0; i<resultList.size(); i++) { sysjgxxbList.add(resultList.get(i)); } }