java向下递归,构造树形结构

 

 

代码逻辑如下:

//xxx组织机构树形列表方法
public List<Organization> xxxTreeOrg(xxx xx){
   //所有的组织机构list
  List<Organization> allOrganizationList = xxxDao.findAllOrgList();

   //所有一级组织机构List
  List<Organization> oneOrganizationList = xxxDao.findOneOrgList();

  for (Organization oneOrganization : oneOrganizationList) {
      oneOrganization.setChild(doOrgIterator(oneOrganization, allOrganizationList));
  }

  return oneOrganizationList; }
//向下递归的方法 private List<Organization> doOrgIterator(Organization oneOrganization, List<Organization> allOrganizationList) {   List<Organization> childList = new ArrayList<>();   for (Organization organization : allOrganizationList) {   if(oneOrganization.getId().intValue() == organization.getPid().intValue()) {     organization.setChild(doOrgIterator(organization, allOrganizationList));     childList.add(organization);    }   }   return childList; }

 

posted @ 2020-07-01 18:27  素净  阅读(1351)  评论(0编辑  收藏  举报