Pagination and Sorting
Let’s learn to enable pagination and sorting capabilities in the JPA repositories.
We'll cover the following...
We'll cover the following...
PagingAndSortingRepository
So far, we’ve integrated our REST APIs for CRUD operations with the database by using JPA,s TodoRepository and TodoTypeRepository repositories. We also extended the CrudRepository interface. In this lesson, we’ll replace the CrudRepository with the PagingAndSortingRepository to enable pagination and sorting features.
TodoRepository extending PagingAndSortingRepository
package io.educative.repositories;import io.educative.domains.Todo;import org.springframework.data.repository.PagingAndSortingRepository;import org.springframework.stereotype.Repository;@Repositorypublic interface TodoRepository extends PagingAndSortingRepository<Todo, Long> {}
TodoTypeRepository extending PagingAndSortingRepository
package io.educative.repositories;import io.educative.domains.TodoType;import org.springframework.data.repository.PagingAndSortingRepository;import org.springframework.stereotype.Repository;@Repositorypublic interface TodoTypeRepository extends PagingAndSortingRepository<TodoType, String> {}
Let’s look at the findAll methods of the PagingAndSortingRepository interface with the Sort and Pageable parameters:
public interface PagingAndSortingRepository<T, ID> extends CrudRepository<T, ID> ...