批量插入集合数据(集合数据量比较大),可以将集合拆分成每次多少条一组,循环插入数据库中。
引入依赖
<dependency><groupId>com.google.guava</groupId><artifactId>guava</artifactId><version>28.0-jre</version></dependency>
引入包
import com.google.common.collect.Lists;
使用
List<Student> list = data.getData().getRecords();if(list!=null && list.size()>0){//每次2000条一组批量插入数据库List<List<Student>> partition = Lists.partition(list, 2000);partition.forEach(f -> {//批量插入vmDao.insertVmData(f);});}