对接入库数据,有时候数据量比较大,需要分批入库,写了一个分批入库的小方法

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);
                }
            }

简单记录使用

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-05-29
  • 2021-06-05
  • 2021-06-26
猜你喜欢
  • 2023-02-05
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-02-09
相关资源
相似解决方案