對接入庫數據,有時候數據量比較大,需要分批入庫,寫了一個分批入庫的小方法
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); } }
簡單記錄使用