对接入库数据,有时候数据量比较大,需要分批入库,写了一个分批入库的小方法
if (!CollectionUtils.isEmpty(student)) { // 计数器 int count = 1; int total = student.size(); List<StudentEntity> stuList = new ArrayList(); for (int f = 0; f < total; f++, count++) { StudentEntity entity = student.get(f); entity.setId(IdUtil.objectId()); stuList .add(entity); //200条入库一次 if (count % 200 == 0) { studentService.insertBatchCustom(stuList); stuList .clear(); count = 1; } } if (!stuList .isEmpty()) { studentService.insertBatchCustom(stuList); } }
简单记录使用