后端真批量新增的使用

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");

相关推荐
super_lzb8 小时前
mybatis拦截器ParameterHandler详解
java·数据库·spring boot·spring·mybatis
CodeAmaz15 小时前
MyBatis 分页插件实现原理(Interceptor 机制 + SQL 改写)
mybatis·分页插件
CodeAmaz15 小时前
MyBatis 如何实现“面向接口”查询
mybatis·面向接口
此剑之势丶愈斩愈烈16 小时前
mybatis-plus乐观锁
开发语言·python·mybatis
雨中飘荡的记忆17 小时前
MyBatis数据源模块详解
mybatis
heartbeat..18 小时前
Java 持久层框架 MyBatis 全面详解(附带Idea添加对应的XML文件模板教程)
java·数据库·intellij-idea·mybatis·持久化
Predestination王瀞潞18 小时前
Java EE数据访问框架技术(第三章:Mybatis多表关系映射-下)
java·java-ee·mybatis
刘一说2 天前
2026年Java技术栈全景图:从Web容器到云原生的深度选型指南(附避坑指南)
java·前端·spring boot·后端·云原生·tomcat·mybatis
独自归家的兔2 天前
Spring Retryable 注解完全指南:从入门到精通,让接口容错更简单
java·spring·mybatis
sunddy_x2 天前
MyBatis 与 SpringBoot 集成入门
spring boot·后端·mybatis