后端真批量新增的使用

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

相关推荐
丑八怪大丑5 小时前
MyBatis
mybatis
从此以后自律10 小时前
MyBatis 与 MyBatis-Plus 完整对比讲解
mybatis
SQL-First布道者14 小时前
Spring JDBC Ultra 十边型战士
java·spring boot·后端·mysql·spring·mybatis
han_hanker2 天前
sql语法 MyBatis <foreach> 标签详解
windows·sql·mybatis
ByWalker_3 天前
web应用技术—MyBatis入门
java·数据库·mybatis·lombok
ylscode3 天前
Cloudflare Workers Cache 深度解析:边缘缓存如何重塑无服务器性能边界
java·spring·mybatis
risc1234565 天前
Roaring Bitmap
java·开发语言·mybatis
Wang's Blog6 天前
JavaWeb快速入门: MyBatis入门与实战
java·mybatis
前端炒粉6 天前
马克思主义基本原理在MyBatis框架中的指导作用探析
mybatis·马克思主义
.Hypocritical.6 天前
MyBatis-Plus笔记
mybatis·mybatisplus