Search code examples
javaspringspring-bootspring-mvcspring-data

Spring Data PagedListHolder second page is show the same data as first page when the page size is greater than or equal the data size


I've the actual data = 25 records and then I sent the request

Page : 1 PageSize : 25

The data return with 25 records correctly but when I try

Page : 2 PageSize : 25

The data return with 25 records same way as Page 1 why the data is not ending on the first page ?
Could you please help me to fix this with any input ?
How can I get correct data on the page for any input?
Here is my code :

PagedListHolder<ObjectResponseDTO> pagedListHolder = new PagedListHolder<>(ObjectResponse);
pagedListHolder.setPage(Request.getPageDesc().getCurrentPage() - 1);
pagedListHolder.setPageSize(Request.getPageDesc().getPageSize());

Solution

  • PagedListHolder is stateful and is on page Request.getPageDesc().getCurrentPage() - 1.

    You need to use the pagedListHolder.nextPage(); method to change the page number status.