//小人

优化mybatis-plus批量新增(只对MySql生效Oracle不生效)

因为mybatis-plus的批量新增是一条一条的耗费资源和慢所以进行批量优化

 

 1.自定义Sql注入器MySqlInjector继承DefaultSqlInjector

复制代码
public class MySqlInjector extends DefaultSqlInjector {

    @Override
    public List<AbstractMethod> getMethodList(Class<?> mapperClass, TableInfo tableInfo) {
        List<AbstractMethod> methodList = super.getMethodList(mapperClass, tableInfo);
        methodList.add(new InsertBatchSomeColumn()); // 添加InsertBatchSomeColumn方法
        return methodList;
    }

}
复制代码

2.然后将自定义的Sql注入器注入

   @Bean
    public MySqlInjector mySqlInjector () {
        return new MySqlInjector();
    }

 3.在需要批量的类引入insertBatchSomeColumn方法

(或者创建个接口继承BaseMapper 让别的接口继承新的BaseMapper)

复制代码
@Mapper
public interface TProcessNodeMapper extends BaseMapper<TProcessNode> {

    /**
     * 批量插入(mysql)
     * @param entityList
     * @return
     */
    Integer insertBatchSomeColumn(Collection<TProcessNode> entityList);
}
复制代码

 4.如果项目内引入了Mybatis联表插件会报

 

posted @   H_Q  阅读(357)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· 阿里巴巴 QwQ-32B真的超越了 DeepSeek R-1吗?
· 【译】Visual Studio 中新的强大生产力特性
· 10年+ .NET Coder 心语 ── 封装的思维:从隐藏、稳定开始理解其本质意义
· 【设计模式】告别冗长if-else语句:使用策略模式优化代码结构
点击右上角即可分享
微信分享提示