- /**
- * 自定义Sql注入
- * @author zy
- */
- public class SqlInjector extends DefaultSqlInjector {
- @Override
- public List
getMethodList(Class> mapperClass, TableInfo tableInfo) { - // 注意:此SQL注入器继承了DefaultSqlInjector(默认注入器),调用了DefaultSqlInjector的getMethodList方法,保留了mybatis-plus的自带方法
- List
methodList = super.getMethodList(mapperClass, tableInfo); - //往父类方法列表中添加了一个新的方法 InsertBatchSomeColumn
- //该方法使用了一个 Lambda 表达式作为参数,逻辑是检查字段填充(fieldFill)是否不等于 FieldFill.UPDATE
- methodList.add(new InsertBatchSomeColumn(i -> i.getFieldFill() != FieldFill.UPDATE));
- return methodList;
- }
- }
- /**
- * mybatisPlus配置类
- * @author zy
- */
- @Configuration
- public class MybatisConfig {
- @Bean
- public MybatisPlusInterceptor mybatisPlusInterceptor() {
- MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor();
- interceptor.addInnerInterceptor(new PaginationInnerInterceptor());
- return interceptor;
- }
- @Bean
- public SqlInjector easySqlInjector(){
- return new SqlInjector();
- }
- }
- public interface SqlInjectorMapper
extends BaseMapper { - /**
- * 批量插入
- */
- Integer insertBatchSomeColumn(Collection
entityList) ; - }
- public interface UserMapper extends SqlInjectorMapper
{ -
- }
A用insertBatchSomeColumn()方法
B用saveBatch()方法
