后端真批量新增的使用

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

相关推荐
williamyi7412 小时前
mybatis报错org/apache/commons/lang3/tuple/Pair] with root cause
apache·mybatis
bing_15817 小时前
MyBatis Mapper 接口的作用,以及如何将 Mapper 接口与 SQL 映射文件关联起来
数据库·sql·mybatis
用户96343902413619 小时前
Mybatis输出可执行的SQL
mybatis
就叫飞六吧1 天前
WangEditor快速实现版
node.js·mybatis
自在如风。1 天前
MyBatis-Plus 使用技巧
java·mybatis·mybatis-plus
鱼骨不是鱼翅2 天前
Mybatis操作数据库----小白基础入门
数据库·mybatis
钢板兽2 天前
Java后端高频面经——Spring、SpringBoot、MyBatis
java·开发语言·spring boot·spring·面试·mybatis
嘵奇2 天前
MyBatis-Plus 注解大全
java·mybatis
曹天骄2 天前
使用 MyBatis XML 和 QueryWrapper 实现动态查询
xml·mybatis