<dependency>
<groupId>com.baomidou</groupId>
<artifactId>mybatis-plus-boot-starter</artifactId>
<version>3.3.2</version>
</dependency>
/**
* 扩展通用 Mapper,支持数据批量插入
*
* @author sunziwen
*/
public interface EasyBaseMapper<T> extends BaseMapper<T> {
/**
* 批量插入 仅适用于mysql
*
* @param entityList 实体列表
* @return 影响行数
*/
Integer insertBatchSomeColumn(Collection<T> entityList);
}
/**
* 支持自定义数据方法注入
*
* @author sunziwen
*/
public class EasySqlInjector extends DefaultSqlInjector {
@Override
public List<AbstractMethod> getMethodList() {
/*防止父类方法无法使用*/
List<AbstractMethod> methodList = super.getMethodList();
methodList.add(new InsertBatchSomeColumn(t -> true));
return methodList;
}
}
@Configuration
public class MybatisPlusConfig {
/**
* 分页插件
*
* @return PaginationInterceptor
*/
@Bean
public PaginationInterceptor paginationInterceptor() {
return new PaginationInterceptor();
}
@Bean
public EasySqlInjector easySqlInjector() {
return new EasySqlInjector();
}
}
@Repository
public interface EventOrderSuppliesMapper extends EasyBaseMapper<EventOrderSupplies> {
}
eventOrderSuppliesMapper.insertBatchSomeColumn(list);