0、简介

MyBaties-Plus 是 MyBaties 的增强版,MyBaties 有的性能它都有,MyBaties 没有的性能它也有。MP 有许多长处,然而这里我只记录批量插入的办法,益处是大数据量速度相对来说很快,有趣味的能够本人做下比照。实现步骤如下。

1、引入 POM

<dependency>  <groupId>com.baomidou</groupId>  <artifactId>mybatis-plus-boot-starter</artifactId>  <version>3.4.3.4</version></dependency>

2、实体类

@TableName("t_a")public class A{}

3、Mapper 接口

public interface AMapperextends BaseMapper<A>{}

4、service 接口

public interface IAService extends IService<A> {}

5、Impl 实现类

public class AServiceImpl extends ServiceImpl<AMapper, A> implements IAService {}

6、MySQL 连贯参数最初上加如下参数 ==(重要)==

# &rewriteBatchedStatements=true 通知 jdbc 要应用批处理jdbc:mysql://ip:3306/t_test?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8&rewriteBatchedStatements=true

7、应用批量插入

public class testService {    @Autowired    private IAService aService;        public void test(List<A> list) {        aService.saveBatch(list);    }}
记录如有不对烦请指出,后行感激