后端真批量新增的使用

1,添加真批量新增抽象接口

public interface EasyBaseMapper extends BaseMapper {

/**

* 批量插入 仅适用于mysql

*

* @return 影响行数

*/

Integer insertBatchSomeColumn(Collection entityList);

}

2,新增类,添加真批量新增的方法

public class InsertBatchSqlInjector extends DefaultSqlInjector {

@Override

public List getMethodList(Class<?> mapperClass) {

List methodList = super.getMethodList(mapperClass);

//添加InsertBatchSomeColumn方法

methodList.add(new InsertBatchSomeColumn());

return methodList;

}

}

3,MybatisPlusConfig 类中添加注册

@Bean

public InsertBatchSqlInjector easySqlInjector () {

return new InsertBatchSqlInjector();

}

4,需要的接口重新继承拥有真批量添加的类

public interface Mapper extends EasyBaseMapper<类名>

5,使用真批量新增

if (list != null && list.size() != 0) {

mapper.insertBatchSomeColumn(list);

}

6,跟一个一个添加,速度减少了90% ,下面是耗时检测

long start = System.currentTimeMillis();

long end = System.currentTimeMillis();

System.out.println("修改客户组管理耗时:"+ (end-start) + "ms");

相关推荐
xbgRS15 小时前
spring整合mybaits
java·spring·mybatis
vHelios1 天前
【电商项目】商品服务模块的问题解决与代码逻辑思考
java·sql·mybatis
敲个大西瓜1 天前
Mybatis核心面试题
mybatis
砍材农夫2 天前
物联网实战|Spring Boot MQTT平台 |emqx broker实战
spring boot·spring·spring cloud·mybatis
Crazy________2 天前
Redis02:库切换、监控与安全配置
linux·redis·云原生·mybatis
xbgRS3 天前
Mybatis源码-核心流程及核心类
java·mybatis
不谈恋爱的猫4 天前
redis哨兵模式
数据库·redis·mybatis
步行cgn4 天前
JNDI 详解:它是什么,为什么用,怎么用?
mybatis
paopaokaka_luck4 天前
基于springboot3+vue3的云南本土影视文旅推荐平台(协同过滤算法、Echarts图形化分析)
前端·spring boot·学习·算法·echarts·mybatis
黄毛火烧雪下4 天前
2026 Java后端面试题总结(持续更新):Spring、MyBatis、Redis、MySQL、多线程
java·spring·mybatis