zoukankan      html  css  js  c++  java
  • Tree数据从后台处理类

    public class TreeUtils {
        /**
         * 使用递归方法建树
         * @param treeNodes
         * @return
         */
        public static List<ProjectBasicInfoDTO> buildByRecursive(List<ProjectBasicInfoDTO> projectBasicInfoDTOs) {
            List<ProjectBasicInfoDTO> trees = new ArrayList<ProjectBasicInfoDTO>();
            for (ProjectBasicInfoDTO projectBasicInfoDTO : projectBasicInfoDTOs) {
                if ("".equals(projectBasicInfoDTO.getpId()) || projectBasicInfoDTO.getpId() == null ) {
                    trees.add(findChildren(projectBasicInfoDTO,projectBasicInfoDTOs));
                }
            }
            return trees;
        }
        
        /**
        * 递归查找子节点
        * @param treeNodes
        * @return
        */
        public static ProjectBasicInfoDTO findChildren(ProjectBasicInfoDTO projectBasicInfoDTO,List<ProjectBasicInfoDTO> projectBasicInfoDTOs) {
            for (ProjectBasicInfoDTO projectBasicInfoDTO2 : projectBasicInfoDTOs) {
                if(projectBasicInfoDTO.getId().equals(projectBasicInfoDTO2.getpId())) {
                    if(projectBasicInfoDTO.getChildren() == null) {
                        projectBasicInfoDTO.setChildren(new ArrayList<ProjectBasicInfoDTO>());
                    }
                    //是否还有子节点,如果有的话继续往下遍历,如果没有则直接返回
                    projectBasicInfoDTO.getChildren().add(findChildren(projectBasicInfoDTO2,projectBasicInfoDTOs));
                }
            }
            return projectBasicInfoDTO;
        }
    }
  • 相关阅读:
    绪论
    Linux回到上次目录
    松下伺服电机控制器参数设置
    更新github上的文件
    pytorch
    从本地上传文件到github
    Linux常用命令
    使用colab训练神经网络
    深度学习模型训练过程
    anaconda安装ubuntu20.4中
  • 原文地址:https://www.cnblogs.com/fengyangcai/p/13643289.html
Copyright © 2011-2022 走看看