因为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); }
标签:return,methodList,批量,MySqlInjector,mybatis,plus,生效,Oracle,public From: https://www.cnblogs.com/HQ0422/p/17039912.html