Skip to content
Advertisement

How to set TotalPages of a PageImpl class in spring boot

I’m converting a Page to a new one by using PageImpl class, but the totalpages attribute has the default value 0. I would like to set totalPages to a specific number. Is it possible to change it?

code

JavaScript

Advertisement

Answer

To get a page as an answer you need to change a line in your code

JavaScript

Case 1 To find maximum pages

JavaScript

Case 2 – Your scenario – From a collection object If want data with pagination then you have to take the help from PageImpl class.

which offer 2 Constructor to do this

JavaScript

where

  1. content – the content of this page(Your collection object).
  2. pageable – the paging information
  3. total – the total amount of items available.

There is also another constructor

JavaScript

Note – This will result in the created Page being identical to the entire List.

User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement