List 递归循环查询所有的 子类别、子子类别、子子子类别…………递归



public List<CheckType> getAllChildTypeList(String pid, boolean isSelf){

CheckType checkType=null;

if(StringUtils.isEmpty(pid)){

List<CheckType> l=checkTypeDao.findByParentNull();

if(CollectionUtils.isEmpty(l)||l.size()==0){

return null;

}

checkType=l.get(0);

}else{

checkType=(CheckType)checkTypeDao.findById(pid);

}

List<CheckType> allList=checkTypeDao.findAllDisableFalse();

List<CheckType> newlist=new ArrayList<CheckType>();

List<CheckType> list=getChildCheckTypeList(newlist,allList,checkType);

if(isSelf){

list.add(checkType);

}

return list;

}

private List<CheckType> getChildCheckTypeList(List<CheckType> newList,List<CheckType> allList,CheckType checkType){

if(null==checkType){return newList;}

for (CheckType ct : allList) {

if(null==ct.getParent()){

continue;

}

if(ct.getParent().getId().equals(checkType.getId())){

newList.add(ct);

getChildCheckTypeList(newList,allList,ct);

}

}

return newList;

}


你可能感兴趣的:(List 递归循环查询所有的 子类别、子子类别、子子子类别…………递归)