//小人

优化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 @ 2023-01-10 13:40  H_Q  阅读(298)  评论(0编辑  收藏  举报