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

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>
相关推荐
流星白龙5 小时前
【Redis】2.Redis重大版本
数据库·redis·junit
流星白龙5 小时前
【Redis】7.Hash表
数据库·redis·哈希算法
流星白龙6 小时前
【Redis】4.基本全局命令
数据库·redis·缓存
码兄科技6 小时前
实战:基于Spring Boot + UniApp的地理信息小程序开发
spring boot·后端·uni-app
王八八。7 小时前
Navicat 17破解版下载安装教程 附安装激活步骤(2026 最新版)
数据库·navicat
Jelena157795857928 小时前
电商运营分析数据比价接口实战:多平台价格监控与智能决策系统
java·大数据·数据库
神明不懂浪漫9 小时前
【第五章】Java中的继承与多态
java·开发语言
流星白龙9 小时前
【Redis】3.Redis安装与命令行客户端
数据库·redis·缓存
凌虚10 小时前
基于 PostgreSQL WAL 构建 CDC 系统:原理与工程实现
数据库·后端·postgresql
BullSmall10 小时前
PostgreSQL 14 pg_dumpall 完整备份指南
数据库·postgresql·oracle