若依框架数据查重问题

工作遇到的问题,顺手记录下

背景:插入和修改数据的其中两个字段作为关联主键不能重复(就是这两个字段不能同时与其他数据中的这两个字段一样,单个重复是没问题的)

核心思路:遍历查找是否重复(小白想问问有时间复杂度更低的写法摸)

//数据查重问题,console打印查重对象的数据,若数据未重复则为undefined
letisNameDuplicate=this.InformationList.find(item=>(item.enterpriseName==this.form.enterpriseName||item.creditCode==this.form.creditCode)&&item.tInformationId!=this.form.tInformationId);
console.log(isNameDuplicate);

一、Controller新增

@PreAuthorize("@ss.hasPermi('system:IuCooperation:list')")
    @GetMapping("/listAll")
    public TableDataInfo listAll()
    {
        startPage();
        TIuCooperationInfo tIuCooperationInfo = new TIuCooperationInfo();
        List<TIuCooperationInfo> list = tIuCooperationInfoService.selectTIuCooperationInfoList(tIuCooperationInfo);
        return getDataTable(list);
    }

二、js新增

export function listIuCooperationAll() {
  return request({
    url: '/system/IuCooperation/listAll',
    method: 'get',
  })
}

三、vue下的data新增

IuCooperationListAll: [],

四、vue下的提交按钮方法改写

submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          this.loading = true;
          listIuCooperationAll().then(response =>{
            this.IuCooperationListAll=response.rows;
            this.loading = false;
            let isNameDuplicate = this.IuCooperationListAll.find(item => (item.professionalName == this.form.professionalName&&item.cooperativeName == this.form.cooperativeName)&&item.tCooperationId != this.form.tCooperationId);
            if (!isNameDuplicate) {
              if (this.form.tCooperationId != null) {
                updateIuCooperation(this.form).then(response => {
                  this.$modal.msgSuccess("修改成功");
                  this.open = false;
                  this.getList();
                });
              } else {
                addIuCooperation(this.form).then(response => {
                  this.$modal.msgSuccess("新增成功");
                  this.open = false;
                  this.getList();
                });
              }
            }else {
              this.$modal.msgError("专业名称和合作企业名称关联重复,请输入正确信息!");
            }
          });
        }
      });
    },

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值