• oracle数据回显时候递归实战


    太简单的两篇递归循环
    orcale 在项目里递归循环实战

    先看资产表T_ATOM_ASSET结构
    在这里插入图片描述
    看业务类别表T_ATOM_BUSI_CATEGORY结构
    在这里插入图片描述

    问题出现

    在这里插入图片描述
    页面显示
    在这里插入图片描述
    实际对应的归属业务分类
    在这里插入图片描述

    涉及到oracle递归实战(这里不会如何直接在atomAsset的seelct里面处理递归回显)

    直接在实现层看atomAssetMapper和atomBusiCategoryMapper处理(这里转来转去数据格式,不知道有啥简单方法不)
    impl

        @Override
        public PageResult<AtomAsset> queryAll(AtomAssetQueryCriteria criteria, Page<Object> page){
            IPage<AtomAsset> all = atomAssetMapper.findAll(criteria, page);
            List<AtomAsset> records = all.getRecords();
    
    
    //        根据每条数据类的busiSort递归向下查找归属业务分类
            if(records.size() > 0 ){
                for (int i = 0; i < records.size(); i++) {
                    String busiSort = records.get(i).getBusiSort();
    //                逗号分隔字符串截取
                    String[] split = busiSort.split(",");
    //                string[] 转List再转Set-----为了去重
                    List<String> strings = new ArrayList<>(Arrays.asList(split));
                    Set<String> taskSet  = new LinkedHashSet<>();
                    taskSet.addAll(strings);
    //                记录最终对应的分类名字结果
                    Set<String> taskSetResult  = new LinkedHashSet<>();
                    for(String item : taskSet){
    //                    根据分类id获取分类名称(递归向下查找)
                        List<String> subCategory = atomBusiCategoryMapper.findSubCategory(Long.parseLong(item));
    //                    根据分类id获取当前自己的分类名称
                        String currentCategoryName = atomBusiCategoryMapper.findCategoryNameByCateforyId(Long.parseLong(item));
                        taskSetResult.addAll(subCategory);
                        taskSetResult.add(currentCategoryName);
                    }
    //                set又转成List返回前端
                    records.get(i).setBusiSortName(new ArrayList<>(taskSetResult));
                }
            }
    //        System.out.println(all);
            return PageUtil.toPage(all);
        }
    

    直接看AtomBusiCategoryMapper.xml的小小递归写法

        <select id="findSubCategory" resultType="java.lang.String">
                select distinct category_name
                from T_ATOM_BUSI_CATEGORY
                start with superior_id = #{categotyId}
                connect by prior category_id = superior_id
        select>
    
        <select id="findCategoryNameByCateforyId" resultType="java.lang.String">
            select category_name
            from T_ATOM_BUSI_CATEGORY
            where category_id = #{categotyId}
        select>
    
  • 相关阅读:
    Q-learning算法实战
    C#:Winform界面中英文切换功能
    ASP.NET 6启动时自动创建MongoDB索引
    【学习笔记22】JavaScript数组的练习题
    【慕伏白教程】 Linux 深度学习服务器配置指北
    Ubuntu Linux adb shell
    vue编写分页组件
    HTML5期末考核大作业,电影网站——橙色国外电影 web期末作业设计网页
    Origin中增加一列并更新绘图
    数据可视化前端技术选型
  • 原文地址:https://blog.csdn.net/tellmewhoisi/article/details/139177879