mybatisplus批量插入
·
yam文件
spring:
datasource:
type: com.alibaba.druid.pool.DruidDataSource
driver-class-name: com.mysql.cj.jdbc.Driver
url: jdbc:mysql://localhost:3306/shop?serverTimezone=GMT%2B8&useSSL=true&rewriteBatchedStatements=true
username: root
password: 123456

@Test
void batchAdd(){
List<User> userList = new ArrayList<>(1000);
long b = System.currentTimeMillis();
for (int i = 0; i < 10000; i++){
User user = new User();
user.setUsername("lmj"+i);
user.setPassword("123456");
user.setMoney(1000);
user.setStatus(1);
userList.add(user);
if(i % 1000 == 0){
userService.saveBatch(userList);
userList.clear();
}
}
long e = System.currentTimeMillis();
System.out.println("耗时:"+(e-b));
}
魔乐社区(Modelers.cn) 是一个中立、公益的人工智能社区,提供人工智能工具、模型、数据的托管、展示与应用协同服务,为人工智能开发及爱好者搭建开放的学习交流平台。社区通过理事会方式运作,由全产业链共同建设、共同运营、共同享有,推动国产AI生态繁荣发展。
更多推荐


所有评论(0)