当前位置: 首页 > 后端技术 > Java

MyBaties-Plus批量存储

时间:2023-04-01 21:25:28 Java

0.简介MyBaties-Plus是MyBaties的增强版,它有MyBaties有的功能,也有MyBaties没有的功能。MP有很多优点,这里我只记录批量插入的方法。优点是大数据量的速度比较快。有兴趣的可以自己对比一下。实施步骤如下。1.引入P??OMcom.baomidoumybatis-plus-boot-starter3.4.3.42.实体类@TableName("t_a")publicclassA{@TableId(value="id",type=IdType.AUTO)privateLongid;}3.Mapper接口publicinterfaceAMapperextendsBaseMapper{}4.Service接口publicinterfaceIAServiceextendsIService{}5.ImplimplementationclasspublicclassAServiceImplextendsServiceImplimplementsIAService{}6.在MySQL连接参数末尾添加如下参数==(重要)==#&rewriteBatchedStatements=true告诉jdbc使用batchjdbc:mysql://ip:3306/t_test?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8&rewriteBatchedStatements=true7,usebatchinsertpublicclasstestService{@AutowiredprivateIAServiceaService;publicvoidtest(Listlist){aService.拯救吧tch(列表);}}如果记录有误,请指出,提前致谢