后端真批量新增的使用

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

相关推荐
老毛肚3 小时前
MyBatis插件原理及Spring集成
java·spring·mybatis
马尔代夫哈哈哈8 小时前
MyBatis 入门与实战:从配置到CRUD一站式指南
mybatis
Jul1en_9 小时前
【MyBatis/plus】核心配置、插件与 MyBatis-Plus 构造器 Wrapper
mybatis
LiZhen79812 小时前
SpringBoot 实现动态切换数据源
java·spring boot·mybatis
我是Superman丶13 小时前
在 PostgreSQL 中使用 JSONB 类型并结合 MyBatis-Plus 实现自动注入,主要有以下几种方案
数据库·postgresql·mybatis
Pluto_CSND13 小时前
基于mybatis-generator插件生成指定数据表的实体类、xml文件和dao层接口
mybatis
indexsunny15 小时前
互联网大厂Java面试实战:微服务与Spring生态技术解析
java·spring boot·redis·kafka·mybatis·hibernate·microservices
手握风云-16 小时前
JavaEE 进阶第十六期:MyBatis,查询请求的生命周期全景图(一)
java·java-ee·mybatis
独断万古他化17 小时前
【SSM开发实战:博客系统】(二)JWT 登录流程、拦截器实现和用户信息接口落地
spring boot·spring·mybatis·博客系统·项目
Pluto_CSND18 小时前
MyBatis 的 XML 文件中特殊字符的处理
mybatis