If you are using Spring Data you can create a interface
that extends to interface
PagingAndSortingRepository that contains additional methods for paging.
The method findAll" receives an object of type Pageable , which contains the criteria for paging, such as quantity of items, current page, which field you want to sort, and whether the sort is ascending or descending.
See an example:
Interface:
TheLongparameteristhetypeoftheUserId
Controller:
tamanho
istheamountofitemsyoushouldhaveonthepage.The findAll" returns an object of type Page that contains the information of the current page: Contents, Quantity, Total Elements, Number of Pages. You can check the documentation which is returned by the