【7.2.5】【db】新增自定义SqlInjector,增加拼sql形式insert的方法

pull/37/head
fengshuonan 2022-09-17 14:54:39 +08:00
parent 3cb033a862
commit 16a2e8e586
3 changed files with 64 additions and 0 deletions

View File

@ -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);
}

View File

@ -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;
/**
* saveBatchvalues
*
* @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;
}
}

View File

@ -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();
}
}