• 递归的使用-- 国民经济行业类别集合递归树


    controller

    private static DCCommUtil commUtil; 
    1

    @RequestMapping("/getALLIndustryTotree") 2 public Result getALLIndustryTotree() { 3 Result result = new Result(); 4 //1、查询所有国民经济行业类别 5 List<industry> industryList=codeService.getALLIndustry(); 6 List<industry> returnIndustryList = new ArrayList<industry>(); 7 //2、遍历国民经济行业类别 8 for (industry industry : industryList) { 9 if (industry.getPid().equals("0")) { 10 //3、调用递归组装树 11 industry = commUtil.buildTree(industryList, industry); 12 returnIndustryList.add(industry); 13 } 14 } 15 try { 16 result = result.buileSuccess(); 17 result.setData(returnIndustryList); 18 } catch (Exception e) { 19 result = result.buileFailure(); 20 result.setData(e.getMessage()); 21 } 22 return result; 23 }

    DCCommUtil.java

     1 public class DCCommUtil {
     2     /**
     3      * 国民经济行业类别集合递归树
     4      * @param list
     5      * @param industry
     6      * @return
     7      */
     8     public static industry buildTree(List<industry> list, industry industry){
     9         List<industry> children = new ArrayList<industry>();
    10         for (industry item : list) {
    11             if (item.getPid().equals(industry.getId())) {
    12                 children.add(buildTree(list, item));
    13             }
    14         }
    15         industry.setChildren(children);
    16         return industry;
    17     }

    industry.java

    1 public class industry {
    2     private String id;
    3     private String pid;
    4     private String singlehyname;
    5     private List<industry> children=new ArrayList();

    mapper.xml         CASE  WHEN

    1 <!-- 查询所有国民经济行业类别 -->
    2     <select id="getALLIndustry" resultType="com.mapuni.datacenter.entity.industry">
    3         select 
    4             id,
    5             (CASE pid WHEN '' THEN '0' WHEN NULL THEN '0' ELSE pid END) as pid, 
    6             singlehyname 
    7         from t_cod_industry
    8     </select>
  • 相关阅读:
    element中表单验证实例
    element中时间选择组件,设置default-value无效
    vue中,基于vue-seamless-scroll的无缝滚动实例
    element 表格多选时,修改选中行的背景色
    计算机组成原理11-DMA、数据完整性、分布式计算、大型DMP系统
    计算机组成原理10-总线、输入输出设备、I/O、机械硬盘、SSD硬盘
    计算机组成原理9-CPU组成、缓存、内存
    java基础-字符串
    SQL Server
    BG.Hive
  • 原文地址:https://www.cnblogs.com/bxbo/p/13921016.html
Copyright © 2020-2023  润新知