当前位置: 首页 > news >正文

mybatis-plus的insertBatchSomeColumn方法实现批量插入

1、编写SQL注入器

@Component("batchInsertInjector")
public class BatchInsertInjector extends DefaultSqlInjector {@Overridepublic List<AbstractMethod> getMethodList(Class<?> mapperClass) {List<AbstractMethod> methodList = super.getMethodList(mapperClass);methodList.add(new InsertBatchSomeColumn());return methodList;}
}

2、自定义Mapper继承BaseMapper

public interface AbstractMapper<T>  extends BaseMapper<T> {Integer SIZE_LIMIT = 3000;/*** 批量插入,借助mybatis-plush的injector实现* @param entities*/void insertBatchSomeColumn(@Param("list") List<T> entities);/*** 分段批量插入* @param entities*/default void segmentBatchInsert(List<T> entities){if (CollectionUtils.isEmpty(entities)) {return;}List<List<T>> partition = Lists.partition(entities, SIZE_LIMIT);for (List<T> part : partition) {insertBatchSomeColumn(part);}}
}

3、实体类的mapper继承自定义mapper

@Mapper
public interface LibraryBusinessInfoMapper extends AbstractMapper<LibraryBusinessInfo> {
}

4、使用批量插入方法

    @Autowiredprivate LibraryBusinessInfoMapper libraryBusinessInfoMapper;@Override@Transactionalpublic int batchAdd(List<AddLibraryInfoReqVo> addLibraryInfoReqVos) {List<LibraryInfo> libraryInfos = ReqVo2Entity.INSTANCE.addLibraryInfos2LibraryInfos(addLibraryInfoReqVos);libraryInfoMapper.segmentBatchInsert(libraryInfos);return libraryInfos.size();}

http://www.dtcms.com/a/511797.html

相关文章:

  • 上海传媒公司艺人seo项目优化案例分析文档
  • 【论文阅读】DiffusionDrive:截断扩散模型用于端到端自动驾驶
  • 解读Time Model Statistics中的PL/SQL 和 SQL执行时间
  • DDD(一)认识领域驱动设计(DDD的概念、主要架构模型)
  • Spring Boot集成Spring Integration全解析
  • MCP功能与架构详解
  • Spring Boot优雅关闭全解析
  • 授权登录网站怎么做网站源码怎么做
  • 网站建设遇到哪些攻击网站开发外贸客户
  • 未来之窗昭和仙君(二十六)通用押金系统开发——东方仙盟筑基期
  • 【案例】Unity 平台访问文件浏览器(汇总)
  • Matlab 曲线拟合
  • 基于CSMA-CA协议的V2X通信MATLAB仿真
  • 基于matlab实现的DnCNN网络
  • 网站一般用什么工具做wordpress英文版切换中文
  • 十大最佳摄影网站windows 版 wordpress
  • ruby 、gem 和 cocoapods的联系与区别
  • Python 圆台体积和表面积计算程序(Program for Volume and Surface area of Frustum of Cone)
  • MySQL索引指南
  • 分销网站制作条件免费机械网站模板
  • day01 pyspark入门和基础环境
  • 公司网站 URL 地址规范
  • 建设一个广告联盟的网站免费祝福网页在线制作
  • 实现Trie(前缀树)
  • 杰理SDK入门教程(六):自定义按键事件
  • gray = roi.clone();和gray = roi;的区别是什么?
  • STM32中MX_TIM2_Init函数和HAL_TIM_Base_MspInit函数区别
  • 【基于Selenium的智能滑块验证码破解技术详解】
  • AI体测设备服务商
  • 网站之间如何做视频交换惠州搜索引擎优化