mysql逗号分隔-mybatis查询同时有的数据以及vue下拉框多选数据传递

mysql分隔

key_pollution_source_type 数值:1,2,3 逗号分隔的
查询有1和99或者1,99同时有的数据总数

查询语句:

select count(t.key_pollution_source_type)
from t_yw_qy_baseinfo t
where t.key_pollution_source_type
regexp ‘(^|,)(1|99)(,|$)’;

xml中不能写

regexp ‘(^|,)(#{keyPollutionSourceType})(,|$)’

;
需要转换一下:
在这里插入图片描述

if(!StringUtils.isBlank(tYwQyBaseinfo.getKeyPollutionSourceType())){
            tYwQyBaseinfo.setKeyPollutionSourceType("(^|,)("+tYwQyBaseinfo.getKeyPollutionSourceType()+")(,|$)");
}

xml中:
在这里插入图片描述

and key_pollution_source_type regexp #{keyPollutionSourceType}

下拉框多选:

在这里插入图片描述
只需要添加一个multiple就可以啦。
在这里插入图片描述
前端可以在添加、修改、查看时候转一下
添加multiple这个

string转数组

1、数组转字符串
data.join(‘,’)
//变成字符串后,以逗号分隔
2、字符串转数组
data.split(‘,’)
//字符串按逗号分隔成数组

所以修改要写这个转一下类型

if (this.form.zw != null && this.form.zw != "") {
          this.form.zw = this.form.zw.split(",");
}

数组转string在提交转一下

if (this.form.zw && this.form.zw.length > 0) {
   this.form.zw = this.form.zw
     .map((a, ai) => {
       return a;
     })
     .join(",");
 } else {
   this.form.zw = "";
 }

查看列表也要转一下

/** 查询用户列表 */
    getList() {
      this.loading = true;
      listUser(this.addDateRange(this.queryParams, this.dateRange)).then(
        (response) => {
          response.rows &&
            response.rows.map((a) => {
              // if ((a.zw && a.zw != "null") || a.zw != "") {
              //   a.zw = a.zw && a.zw.split(",");
              // }
              if (a.zw != null && a.zw != "") {
                a.zw = a.zw.split(",");
              }
            });
          this.userList = response.rows;
          this.total = response.total;
          this.loading = false;
        }
      );
    },
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值