java数据分批插入处理

	  List<ComponentTo> componentList = new ArrayList<>();
      if (CollectionUtils.isNotEmpty(componentList)) {
        // 数据总数
        int totalCount = componentList.size();
        // 页大小
        int pageSize = 1000;
        // 分批上传数据
        int lastPageSize = totalCount % pageSize;
        // 总页数
        int totalPage = lastPageSize > 0 ? totalCount / pageSize + 1 : totalCount / pageSize;
        for (int p = 1; p <= totalPage; p++) {
          if (lastPageSize == 0) {
            componentDao.addAutoList(componentList.subList((p - 1) * pageSize, pageSize * p));
          } else {
            if (p == totalPage) {
              componentDao.addAutoList(componentList.subList((p - 1) * pageSize, totalCount));
            } else {
              componentDao.addAutoList(componentList.subList((p - 1) * pageSize, pageSize * p));
            }
          }
          TimeUnit.MILLISECONDS.sleep(50);
        }
      }
上一篇:页码数pageSize


下一篇:【测试开花】三、项目管理-后端-实现列表接口(含分页、模糊查询)