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

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>
相关推荐
lifewange7 分钟前
Redis 集合(Set)运算完全指南
数据库·chrome·redis
TDengine (老段)15 分钟前
TDengine RAFT共识协议 — 选举、日志复制、快照与仲裁
android·大数据·数据库·物联网·架构·时序数据库·tdengine
cheems952731 分钟前
[Spring MVC] 统一功能与拦截器实践总结
java·spring·mvc
Full Stack Developme1 小时前
Spring Boot 事务管理完整教程
java·数据库·spring boot
城管不管2 小时前
前后端远程协作
java
青云计划2 小时前
Feed流
java·后端·spring
java1234_小锋2 小时前
String、StringBuilder、StringBuffer的区别?
java·开发语言
星原望野2 小时前
JAVA集合:List、Set和Map
java·开发语言·list·set·map·集合
2601_957787582 小时前
星链引擎矩阵系统:插件化多平台 API 网关与账号级隔离技术实践
java·矩阵·插件化架构
多敲代码防脱发3 小时前
Spring进阶(容器实现)
java·开发语言·后端·spring