当前使用版本(必填,否则不予处理)
3.5.1
该问题是如何引起的?(确定最新版也有问题再提!!!)
根据主键批量新增或保存saveOrUpdateBatch()时,insert或update语句会重复执行2次
- org.apache.ibatis.executor包, BatchExecutor类,doFlushStatements()方法
- clear前会executeBatch()一遍sql
重现步骤(如果有就写完整)
- 调用ServiceImpl中
saveOrUpdateBatch()方法 - 在批量执行的过程中:
ServiceImpl.java:180:sqlSession.selectList(getSqlStatement(SqlMethod.SELECT_BY_ID), entity)- 上述代码查询语句 执行前会调用
doFlushStatements()方法,导致上一条insert或update语句会重复执行
具体代码定位
| 包 | 类 | 行 | 方法 | 代码 |
|---|---|---|---|---|
| com.baomidou.mybatisplus.extension.service.impl | ServiceImpl | 180 | saveOrUpdateBatch() | sqlSession.selectList() |
| org.apache.ibatis.executor | BatchExecutor | 123 | doFlushStatements() | stmt.executeBatch() |
日志
time: 9ms, SQL: SELECT goods_id,external_goods_id,name,img,description,price,category_id,status,check_status,relation_shop_id,relation_alias_id,platform,is_delete,create_time,update_time FROM goods WHERE goods_id=3560800320777010953
time: 0ms, SQL: INSERT INTO goods ( goods_id, external_goods_id, name, img, description, price, status, check_status, relation_shop_id, platform, create_time, update_time ) VALUES ( 3560800320777010953, 3560800320777010953, '【工厂直销9.9元2个】不锈钢可伸缩痒痒挠 抓痒抓背神器' ...
time: 1ms, SQL: INSERT INTO goods ( goods_id, external_goods_id, name, img, description, price, status, check_status, relation_shop_id, platform, create_time, update_time ) VALUES ( 3560800320777010953, 3560800320777010953, '【工厂直销9.9元2个】不锈钢可伸缩痒痒挠 抓痒抓背神器' ...
time: 0ms, SQL: SELECT goods_id,external_goods_id,name,img,description,price,category_id,status,check_status,relation_shop_id,relation_alias_id,platform,is_delete,create_time,update_time FROM goods WHERE goods_id=3559881187105329830
time: 0ms, SQL: INSERT INTO goods ( goods_id, external_goods_id, name, img, description, price, status, check_status, relation_shop_id, platform, create_time, update_time ) VALUES ( 3559881187105329830, 3559881187105329830, '【厂家直销】钢笔式登山棍伸缩三节防身甩手棍', 'http ...
time: 1ms, SQL: INSERT INTO goods ( goods_id, external_goods_id, name, img, description, price, status, check_status, relation_shop_id, platform, create_time, update_time ) VALUES ( 3559881187105329830, 3559881187105329830, '【厂家直销】钢笔式登山棍伸缩三节防身甩手棍', 'http ...
time: 0ms, SQL: SELECT goods_id,external_goods_id,name,img,description,price,category_id,status,check_status,relation_shop_id,relation_alias_id,platform,is_delete,create_time,update_time FROM goods WHERE goods_id=3559873681650005743
time: 0ms, SQL: INSERT INTO goods ( goods_id, external_goods_id, name, img, description, price, status, check_status, relation_shop_id, platform, create_time, update_time ) VALUES ( 3559873681650005743, 3559873681650005743, '【防盗消磁卡包】多功能不锈钢消磁卡盒 再也不怕卡消磁了' ...
https://user-images.githubusercontent.com/57031463/181283147-2f1eb081-7c5b-46d3-974f-e6affe803081.mp4
Comment From: nieqiurong
指定modulelist=com.baomidou.mybatisplus.extension.p6spy.MybatisPlusLogFactory,com.p6spy.engine.outage.P6OutageFactory试过了吗?
https://baomidou.com/pages/833fab/
Comment From: fsongs
谢谢 可以了