MyBaties-Plus 批量入库
MyBaties-Plus 是 MyBaties 的增强版,MyBaties 有的功能它都有,MyBaties 没有的功能它也有。MP 有许多优点,但是这里我只记录批量插入的方法,好处是大数据量速度相对来说很快,有兴趣的可以自己做下对比。实现步骤如下。
1、引入 POM
com.baomidou mybatis-plus-boot-starter 3.4.3.4
2、实体类
@TableName("t_a")
public class A{}
3、Mapper 接口
public interface AMapperextends BaseMapper{}
4、service 接口
public interface IAService extends IService {}
5、Impl 实现类
public class AServiceImpl extends ServiceImplimplements 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 list) {
aService.saveBatch(list);
}
}
记录如有不对烦请指出,先行感谢