后端真批量新增的使用

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

相关推荐
写了20年代码的老程序员5 小时前
写了 20 年 Java,我受够了 MyBatis 的 4 个瞬间
mybatis·orm
斯特凡今天也很帅12 小时前
新建数据源报错No bean named ‘SqlSessionFactorykf‘ available
java·数据库·spring boot·mybatis
未若君雅裁1 天前
MyBatis 一级缓存、二级缓存与清理机制
java·缓存·mybatis
Simon523141 天前
MyBatis三大核心文件:Entity、DAO、Mapper
mybatis
MandalaO_O1 天前
MyBatis:核心概念 + 环境搭建 + CRUD
java·tomcat·mybatis
XS0301061 天前
MyBatis基础实战笔记一
笔记·mybatis
噢,我明白了1 天前
MyBatis-Plus的引入和配置
java·tomcat·mybatis
霸道流氓气质2 天前
Spring Boot + MyBatis-Plus 实现异常隔离的 Upsert 数据落库(含远程调用数据补全)
spring boot·后端·mybatis
Devin~Y2 天前
大厂Java面试实战:Spring Boot微服务、Redis缓存、Kafka消息队列与Spring AI RAG
java·spring boot·redis·kafka·mybatis·spring mvc·hikaricp
Don.TIk2 天前
ChapterOne-搭建项目骨架
java·spring·spring cloud·mybatis