- 添加依赖
com.baomidou
mybatis-plus-boot-starter
3.4.2
com.baomidou
mybatis-plus-extension
3.4.2
- 构建三个配置-推荐放一个包里面
/ * 扩展通用 Mapper,支持数据批量插入 * * @author sunziwen */ public interface EasyBaseMapper
extends BaseMapper
{ / * 批量插入 仅适用于mysql * * @param entityList 实体列表 * @return 影响行数 */ Integer insertBatchSomeColumn(Collection
entityList); }
/ * 支持自定义数据方法注入 * * @author sunziwen */ public class EasySqlInjector extends DefaultSqlInjector { @Override public List
getMethodList(Class
mapperClass) { /*防止父类方法无法使用*/ List
methodList = super.getMethodList(mapperClass); methodList.add(new InsertBatchSomeColumn()); return methodList; } }
@Configuration public class MybatisPlusConfig { / * 分页插件 * * @return PaginationInterceptor */ @Bean public PaginationInterceptor paginationInterceptor() { return new PaginationInterceptor(); } @Bean public EasySqlInjector easySqlInjector() { return new EasySqlInjector(); } }
- 让原本继承BaseMapper
<实体>
的Dao层改为继承EasyBaseMapper
<实体>实体>
实体> 
- service层已经可以使用批量操作了

- 完工!如有问题咨询博主V:sunziwen3366
发布者:全栈程序员-站长,转载请注明出处:https://javaforall.net/208311.html原文链接:https://javaforall.net
