重写mybatis-plus的saveUpdate方法
重写mybatis-plus的saveUpdate方法
1.问题出现
同步外部数据的时候,如果需要同步逻辑删除的数据,mybatis-plus的saveOrUpdate||saveOrUpdateBath方法底层根据先查出数据数据是否存在,存在则更新不存在则新增,数据逻辑删除时,mybatis-plus查询不出来会执行插入造成主键冲突异常
2.问题解决(重写方法)
Mapper.java
public interface MdmCustomerBankInfoMapper extends BaseMapper<MdmCustomerBankInfo> {
int saveOrUpdate(MdmCustomerBankInfo list);
int saveOrUpdateBatch(List<MdmCustomerBankInfo> list);
}
Mapper.xml
saveOrUpdate
<update id="selfSaveOrUpdateBatch">
INSERT INTO mdm_customer_bank_info (id,customer_id,account_holder_name,bank_country,bank_account_num,bank_name,
bank_branch_code,created_by,created_time,updated_by,updated_time,is_deleted) SELECT * FROM (
SELECT
#{item.id} as id,
#{item.customerId} as customer_id,
#{item.accountHolderName} as account_holder_name,
#{item.bankCountry} as bank_country,
#{item.bankAccountNum} as bank_account_num,
#{item.bankName} as bank_name,
#{item.bankBranchCode} as bank_branch_code,
#{item.createdBy} as created_by,
#{item.createdTime} as created_time,
#{item.updatedBy} as updated_by,
#{item.updatedTime} as updated_time,
#{item.isDeleted} as is_deleted
FROM DUAL
) t2
on DUPLICATE KEY UPDATE customer_id=t2.customer_id,account_holder_name=t2.account_holder_name,bank_country=t2.bank_country,bank_account_num=t2.bank_account_num,
bank_name=t2.bank_name,bank_branch_code=t2.bank_branch_code,
created_by=t2.created_by,created_time=t2.created_time,updated_by=t2.updated_by,updated_time=t2.updated_time,is_deleted = t2.is_deleted
</update>
saveOrUpdateBath
<update id="selfSaveOrUpdateBatch">
INSERT INTO mdm_customer_bank_info (id,customer_id,account_holder_name,bank_country,bank_account_num,bank_name,
bank_branch_code,created_by,created_time,updated_by,updated_time,is_deleted) SELECT * FROM (
<foreach collection="list" item="item" index="index" separator="union">
SELECT
#{item.id} as id,
#{item.customerId} as customer_id,
#{item.accountHolderName} as account_holder_name,
#{item.bankCountry} as bank_country,
#{item.bankAccountNum} as bank_account_num,
#{item.bankName} as bank_name,
#{item.bankBranchCode} as bank_branch_code,
#{item.createdBy} as created_by,
#{item.createdTime} as created_time,
#{item.updatedBy} as updated_by,
#{item.updatedTime} as updated_time,
#{item.isDeleted} as is_deleted
FROM DUAL
</foreach>
) t2
on DUPLICATE KEY UPDATE customer_id=t2.customer_id,account_holder_name=t2.account_holder_name,bank_country=t2.bank_country,bank_account_num=t2.bank_account_num,
bank_name=t2.bank_name,bank_branch_code=t2.bank_branch_code,
created_by=t2.created_by,created_time=t2.created_time,updated_by=t2.updated_by,updated_time=t2.updated_time,is_deleted = t2.is_deleted
</update>
重写mybatis-plus的saveUpdate方法的更多相关文章
- 什么情况下才要重写Objective-C中的description方法
特别注意: 千万不要在description方法中同时使用%@和self,同时使用了%@和self,代表要调用self的description方法,因此最终会导致程序陷入死循环,循环调用descrip ...
- 创建如下三个类:(People类中的三个方法分别输出一些信息,ChinaPeople 和AmericanPeople类重写父类的三个方法)。
创建如下三个类:(People类中的三个方法分别输出一些信息,ChinaPeople 和AmericanPeople类重写父类的三个方法). ackage com.chuoji.text01; pub ...
- spring与mybatis三种整合方法
spring与mybatis三种整合方法 本文主要介绍Spring与Mybatis三种常用整合方法,需要的整合架包是mybatis-spring.jar,可通过链接 http://code.googl ...
- 重写类的Equals以及重写Linq下的Distinct方法
当自定义一个类的时候,如果需要用到对比的功能,可以自己重写Equals方法,最整洁的方法是重写GetHashCode()方法. 但是,这个方法只适用于对象自身的对比(如if(a==b))以及字典下的C ...
- MyBatis学习--mybatis开发dao的方法
简介 使用Mybatis开发Dao,通常有两个方法,即原始Dao开发方法和Mapper接口开发方法. 主要概念介绍: MyBatis中进行Dao开发时候有几个重要的类,它们是SqlSessionFac ...
- 四 mybatis开发dao的方法
mybatis开发dao的方法 1.1 SqlSession使用范围 1.1.1 SqlSessionFactoryBuilder //以流的方式读取总的配置文件 Reader rea ...
- Mybatis的Mapper接口方法不能重载
今天给项目的数据字典查询添加通用方法,发现里边已经有了一个查询所有数据字典的方法 List<Dict> selectDictList(); 但我想设置的方法是根据数据字典的code查询出所 ...
- 为什么要重写hashCode()方法和equals()方法及如何重写
我想写的问题有三个: 1.首先我们为什么需要重写hashCode()方法和equals()方法 2.在什么情况下需要重写hashCode()方法和equals()方法 3.如何重写这两个方法 **** ...
- mybatis中的updateByExampleSelective方法怎么使用
mybatis中的updateByExampleSelective方法怎么使用.sendDetailMapper.updateByExampleSelective(sendDetail, m);参数m ...
- 为什么要重写hashcode方法和equals方法
我们可能经常听到说重写equals方法必须重写hashcode方法,这是为什么呢?java中所有的类都是Object的子类,直接上object源码 /* * Copyright (c) 1994, 2 ...
随机推荐
- new与delete只能被重载为成员函数;而<<等只能被重载为非成员函数
链接:https://www.nowcoder.com/questionTerminal/5760864337084de6891a9944f41e60f4来源:牛客网 应用程序可以将重载的new/de ...
- 梦想云图Node.JS服务 (网页CAD,在线CAD )
说明 后台提供梦想Node.JS服务,方便调用控件后台功能,Windows服务程序所在目录:Bin\MxDrawServer\Windows,Linux服务程序所在目录:Bin\Linux\MxDra ...
- debian11用iso制作本地apt源
摘抄记录,原文链接: https://blog.csdn.net/leejearl/article/details/122708953?spm=1001.2101.3001.6650.1&ut ...
- MAC 不带XIB新建ViewController
- (void)loadView{ NSView *view = [[NSView alloc]init]; self.view = view; } MAC 开发的小伙伴
- Qt 一键部署脚本
echo "begin deploying..." echo Setting up environment for Qt usage... set PATH=C:\Qt\Qt5.8 ...
- laravel service provider 1
可以理解成分两步: 配置.register, 因为只有配置了才有被调用去register, 也许不配置直接在appserviceProvider里面可以直接生效.... service: 具体工作的类 ...
- [*]Quadratic Residual Networks: A New Class of Neural Networks for Solving Forward and Inverse Problems in Physics Involving PDEs
Accepted by SIAM International Conference on Data Mining (SDM21) 本文提出了二次残差网络,通过在应用激活函数之前,添加二次残差项到输入的 ...
- javascript【应用】debounce和throttle
debounce防抖 在事件被触发n秒后再执行回调,如果在这n秒内又被触发,则重新计时:典型的案例就是输入搜索:输入结束后n秒才进行搜索请求,n秒内又输入的内容,就重新计时. <div id=& ...
- docker-compose 搭建 redis 集群
准备配置文件 bind 0.0.0.0 # redis端口 port ${PORT} requirepass redispwd # 关闭保护模式 protected-mode no # 开启集群 cl ...
- VUE前端请求跨域问题解决
解决方法: vue.config.js文件配置: module.exports = { devServer: { open: true, host: '192.168.1.193', port: 80 ...