mirror of https://gitee.com/stylefeng/roses
【7.2.5】【db】新增自定义SqlInjector,增加拼sql形式insert的方法
parent
3cb033a862
commit
16a2e8e586
|
@ -0,0 +1,25 @@
|
|||
package cn.stylefeng.roses.kernel.db.mp.injector;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 加了拓展方法的BaseMapper
|
||||
* <p>
|
||||
* 目前添加自定义InsertBatch方法
|
||||
*
|
||||
* @author fengshuonan
|
||||
* @date 2022/9/17 14:24
|
||||
*/
|
||||
public interface CustomBaseMapper<T> extends BaseMapper<T> {
|
||||
|
||||
/**
|
||||
* 批量插入,拼接insert方式,提高效率
|
||||
*
|
||||
* @author fengshuonan
|
||||
* @date 2022/9/17 14:27
|
||||
*/
|
||||
int insertBatchSomeColumn(List<T> entityList);
|
||||
|
||||
}
|
|
@ -0,0 +1,27 @@
|
|||
package cn.stylefeng.roses.kernel.db.mp.injector;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.FieldFill;
|
||||
import com.baomidou.mybatisplus.core.injector.AbstractMethod;
|
||||
import com.baomidou.mybatisplus.core.injector.DefaultSqlInjector;
|
||||
import com.baomidou.mybatisplus.core.metadata.TableInfo;
|
||||
import com.baomidou.mybatisplus.extension.injector.methods.InsertBatchSomeColumn;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 自定义,针对saveBatch的优化,改为一次拼接多个values插入到库
|
||||
*
|
||||
* @author fengshuonan
|
||||
* @date 2022/9/17 14:23
|
||||
*/
|
||||
public class CustomInsertBatchSqlInjector extends DefaultSqlInjector {
|
||||
|
||||
@Override
|
||||
public List<AbstractMethod> getMethodList(Class<?> mapperClass, TableInfo tableInfo) {
|
||||
List<AbstractMethod> methodList = super.getMethodList(mapperClass, tableInfo);
|
||||
// 例: 不要指定了 update 填充的字段
|
||||
methodList.add(new InsertBatchSomeColumn(i -> i.getFieldFill() != FieldFill.UPDATE));
|
||||
return methodList;
|
||||
}
|
||||
|
||||
}
|
|
@ -26,6 +26,7 @@ package cn.stylefeng.roses.kernel.db.starter;
|
|||
|
||||
import cn.stylefeng.roses.kernel.db.mp.dbid.CustomDatabaseIdProvider;
|
||||
import cn.stylefeng.roses.kernel.db.mp.fieldfill.CustomMetaObjectHandler;
|
||||
import cn.stylefeng.roses.kernel.db.mp.injector.CustomInsertBatchSqlInjector;
|
||||
import com.baomidou.mybatisplus.autoconfigure.MybatisPlusAutoConfiguration;
|
||||
import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
|
||||
import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor;
|
||||
|
@ -108,4 +109,15 @@ public class GunsMyBatisPlusAutoConfiguration {
|
|||
return new CustomDatabaseIdProvider();
|
||||
}
|
||||
|
||||
/**
|
||||
* 自定义sqlInjector
|
||||
*
|
||||
* @author fengshuonan
|
||||
* @date 2022/9/17 14:28
|
||||
*/
|
||||
@Bean
|
||||
public CustomInsertBatchSqlInjector customInsertBatchSqlInjector() {
|
||||
return new CustomInsertBatchSqlInjector();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue