I am referring the example in this blog - https://www.logicbig.com/tutorials/spring-framework/spring-data/pagination-returning-page.html
Pageable pageable = PageRequest.of(0, 500);
while (true) {
page = repo.findByDept("Sales", pageable);
int number = page.getNumber();
int numberOfElements = page.getNumberOfElements();
int size = page.getSize();
long totalElements = page.getTotalElements();
int totalPages = page.getTotalPages();
System.out.printf("page info - page number %s, numberOfElements: %s, size: %s, "
+ "totalElements: %s, totalPages: %s%n",
number, numberOfElements, size, totalElements, totalPages);
List<Employee> employeeList = page.getContent();
employeeList.forEach(employee -> updateDept());
if (!page.hasNext()) {
break;
}
pageable = page.nextPageable();
}
Here, after reading the first page, I am modifying the dept for all the entries returned in the Page. Hence, when the 2nd page is fetched the total no. of pages change. This results in only partial data to be changed. For example, the code retrieves, page 1 of 5, then page 2 of 4 and page 3 of 3 and ends. Is there a way to refresh the page number at each iteration along with the total page or a better approach for this?