From the course: Spring Data
Unlock this course with a free trial
Join today to access over 25,300 courses taught by industry experts.
Paging and sorting - Spring Tutorial
From the course: Spring Data
Paging and sorting
- [Instructor] In our StaffDao class, there is a method to look up a subset of the staff entities. This subset is referred to as a page. The first parameter is the page number, and the second is the size of the page. This method calculates the actual record numbers with the setFirstResult and setMaxResult on the query object and hard codes a sort in the JPQL on the last name of the staff member. I'm happy to say that Spring Data provides a better out-of-the-box approach to paging and sorting, rendering this method completely unnecessary. In this video, we're going to learn just that, query methods for paging and sorting. So how is this done? There is a PagingAndSortingRepository interface that overloads the findAll method in the Spring Data Sort and Spring Data Pageable parameters, and the JpaRepository interface already extends from PagingAndSortingRepository. So, all of our repo interfaces in our project already have these methods available. Plus, query methods can apply paging and…