liveBook · Manning

PagingAndSortingRepository

As explained in Spring Start Here, Second Edition

PagingAndSortingRepository is a Spring Data repository interface that adds paging and sorting operations to CRUD repository operations.

PagingAndSortingRepository is a Spring Data contract for repositories that need both basic CRUD operations and the ability to sort records or retrieve them in pages. It extends CrudRepository, so choose it when CRUD alone is not enough. section 14.2

Define a repository interface that extends PagingAndSortingRepository to request these capabilities. Spring provides a bean implementing that contract for other application components to inject. If an application only needs CRUD, CrudRepository is the simpler choice. section 14.2

Figure 14.6 To implement your app’s repositories using Spring Data, you extend specific interfaces. The main interfaces that represent Spring Data contracts are Repository, CrudRepository, and PagingAndSortingRepository. You extend one of these contracts to implement your app’s persistence capabilities.

The diagram compares the main Spring Data repository contracts and shows where PagingAndSortingRepository fits. section 14.2

How Spring Start Here, Second Edition covers it

How deep it goes
Defines its place above CrudRepository and describes its added operations, without detailing their method signatures.
Examples
Contrasts choosing CrudRepository for CRUD-only needs with choosing PagingAndSortingRepository when sorting and paging are needed.
What you can do after
Apply it by defining a repository interface that extends the contract and injecting its implementing bean where needed.
How it connects
Connects Spring Data Repository and CrudRepository through interface inheritance and interface segregation.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Spring Start Here, Second Edition. The section links point to the parts of the book it draws on.