表格状态码转换,其他索引串转成名字

1.问题分析

原数据库

关联指标为数字串的形式,每个小数对应的是另一张表index的属性,我们想知道对应指标的名称,怎么在这里下面这种形式呢?

两种思路:

1.修改在后端处理,把后端关联指标部分修改成图二的字符串。

2.修改在前端处理,图一这张表数据传到后端,相关联表也传到后端,图一这种数字字符串用spilt方法相切形成数组,循环匹配index在数组里面的数据。

后端方法:

java 复制代码
    public List<FaReviewQuestion> selectFaReviewQuestionList(FaReviewQuestion faReviewQuestion)
    {
        //查出faReviewQuestion条件查询得到的数据
        List<FaReviewQuestion> list=faReviewQuestionMapper.selectFaReviewQuestionList(faReviewQuestion);
        //遍历每一条数据
        for (FaReviewQuestion reviewQuestion : list) {
            //找到FaReviewQuestion对象的RuleIndex属性,并且使用split方法切割
            String indexs=reviewQuestion.getRuleIndex();
            String[] arrs=indexs.split(",");
            //定义一个字符串类型拼接字符串
            String newIndex="";
            //查询FaReviewRuleStudent表中index在数组中的数据使用的where index in (....) 动态sql或mybatisPlus,因为我这个表有特殊字符,所以用的动态sql
            List<FaReviewRuleStudent> list1=faReviewRuleStudentMapper.selectUsersByIds(Arrays.asList(arrs));
            for (FaReviewRuleStudent faReviewRuleStudent : list1) {
                //拼接每个指标的名称
                newIndex=newIndex+" "+faReviewRuleStudent.getName()+" ";
            }
            //把指标中的数字串替换为名称字符串
            reviewQuestion.setRuleIndex(newIndex);
        }
        return list;
    }

动态sql:

XML 复制代码
<select id="selectUsersByIds"  resultMap="FaReviewRuleStudentResult">
        SELECT * FROM fa_review_rule_student
        WHERE `index` IN
        <foreach collection="list" item="id" open="(" separator="," close=")">
            #{id}
        </foreach>
    </select>
相关推荐
科技块儿11 小时前
IP定位技术:游戏反外挂体系中的精准识别引擎
数据库·tcp/ip·游戏
衫水11 小时前
[特殊字符] MySQL 常用指令大全
数据库·mysql·oracle
卓怡学长11 小时前
m115乐购游戏商城系统
java·前端·数据库·spring boot·spring·游戏
2501_9445264211 小时前
Flutter for OpenHarmony 万能游戏库App实战 - 蜘蛛纸牌游戏实现
android·java·python·flutter·游戏
打工的小王12 小时前
java并发编程(三)CAS
java·开发语言
小句12 小时前
SQL中JOIN语法详解 GROUP BY语法详解
数据库·sql
尤老师FPGA12 小时前
使用ZYNQ芯片和LVGL框架实现用户高刷新UI设计系列教程(第四十五讲)
android·java·ui
星火开发设计13 小时前
C++ 函数定义与调用:程序模块化的第一步
java·开发语言·c++·学习·函数·知识
cypking13 小时前
二、前端Java后端对比指南
java·开发语言·前端
阿杰 AJie13 小时前
MySQL 里给表添加索引
数据库·mysql