后端真批量新增的使用

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 小时前
【MyBatis Exception】省略动态SQL中的‘‘,会造成Runtime Exception
java·服务器·mybatis
暴力袋鼠哥20 小时前
基于 SpringBoot + Vue3 的社区医院管理系统实战(含 AI 问诊 + 电子病历 PDF 导出
java·spring boot·intellij-idea·mybatis
亓才孓1 天前
[SprintBootException]BindingException: Invalid bound statement (not found)
mybatis
番茄去哪了1 天前
苍穹外卖day05----店铺营业状态设置
java·数据库·ide·redis·git·maven·mybatis
前路不黑暗@1 天前
Java项目:Java脚手架项目的 C 端用户服务(十五)
java·开发语言·spring boot·学习·spring cloud·maven·mybatis
亓才孓2 天前
[Mybatis]Mybatis框架
java·数据库·mybatis
IT枫斗者2 天前
MyBatis批量插入性能优化:从5分钟到3秒的工程化实践
前端·vue.js·mysql·mongodb·性能优化·mybatis
亓才孓2 天前
[Mybatis]MyBatisSystemException(由于Connection的encoding引起的)
java·开发语言·mybatis
那我掉的头发算什么2 天前
【图书管理系统】基于Spring全家桶的图书管理系统(下)
java·数据库·spring boot·后端·spring·mybatis
疯狂敲代码的老刘3 天前
MyBatis Generator GUI 下载安装教程 可视化MyBatis代码生成
java·mybatis·mybatis-ui