后端真批量新增的使用

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

相关推荐
bekote8 小时前
mybatis-plus-generator模版
mybatis
cyforkk13 小时前
MyBatis Plus 字段自动填充:生产级实现方案与原理分析
mybatis
九皇叔叔13 小时前
【03】SpringBoot3 MybatisPlus BaseMapper 源码分析
java·开发语言·mybatis·mybatis plus
马猴烧酒.18 小时前
【Mybatis出现bug】应为 <statement> 或 DELIMITER,得到 ‘id‘
java·bug·mybatis
一只程序熊19 小时前
SpringBoot class java.lang.String cannot be cast to class java.lang.Long
spring·mybatis
赵得C20 小时前
Tauri 中嵌入百度网页:从 iframe 到 Webview 的迁移实践
spring boot·mybatis·tauri·桌面开发
小北方城市网21 小时前
MyBatis-Plus 生产级深度优化:从性能到安全的全维度方案
开发语言·redis·分布式·python·缓存·性能优化·mybatis
信码由缰21 小时前
MyBatis Dynamic SQL 入门指南
python·sql·mybatis
九皇叔叔1 天前
【04】SpringBoot3 MybatisPlus 查询(Mapper)
java·mybatis·mybatis plus
SamRol1 天前
达梦数据库指令 及 在Spring Boot + MyBatis-Plus上的使用
java·数据库·spring boot·mybatis·达梦·intellij idea