InterviewSolution
Saved Bookmarks
| 1. |
Which repository helps to fetch data for pagination and sorting from the database? |
|
Answer» In addition to the CrudRepository, there is a PagingAndSortingRepository that adds additional methods to ease paginated access to entities: public interface PagingAndSortingRepository<T, ID extends Serializable> extends CrudRepository<T, ID> { Iterable<T> findAll(SORT sort); Page<T> findAll(Pageable pageable); }ACCESSING the third page of Userby a page size of 10 you COULD simply do something like this PagingAndSortingRepository<User, Long> repository = // ... get access to a bean Page<User> users = repository.findAll(NEW PageRequest(2, 10)); |
|