If you are using Spring Data you can create a interface
that extends the interface
Pagingandsortingrepository containing additional methods for paging.
The method findAll receives an object of the type Pageable, which contains the criteria for paging, such as number of items, current page, which field you want to sort and whether the ordering is ascending or descending.
Take an example:
Interface:
The Long parameter is the User Id type
Controller:
The tamanho
is the number of items you should have on the page.
The method findAll returns an object of type Page which contains the information on the current page: Content, Quantity, Total Elements, Number of Pages. You can check on documentation what is returned by the method
You are using Spring Data?
– adelmo00