Usage of Interfaces, Classes, and Methods Once we have our PageRequest object, now we can pass it to the repository methods. here the page number starts from 0 indexes. We can pass the page number and page size as parameters to the of() method. PageRequest provides the following static method – Pageable pages = PageRequest.of(pageNumber, pageSize) Once we extend the repository, we just need to create the object PageRequest object which is the implementation class of the Pageable interface. Returns a Page of entities meeting the paging restriction provided in the Pageable object.Įven we can use JPARepository instead, which extends the PagingAndSortingRepository To add paging support to our Repositories, we need to extend the PagingAndSortingRepository interface rather than the basic CrudRepository interface.īy extending the repository PagingAndSortingRepository, we get the following method – Page findAll(Pageable pageable) Rather than fetching all the records from the database, we can fetch the records on pages with a specific size. Data JPA provides pagination support out of the box. Pagination is often helpful when we have a large dataset and we want to present it to the user in smaller chunks. Usage of Interfaces, Classes, and Methods.