Sorting query results
In the course of this section, we will learn different techniques that can be used to sort query results with Spring Data JPA. We will also learn the guidelines that we can use to select a proper sorting method for each situation.
Sorting with method name
If we are building our queries by using the query generation from the method name strategy, we can sort query results by the following steps:
- Creating a query method
- Modifying an existing service method to use the new query method.
Creating the query method
When we are building our queries by using the query generation from the method name strategy, we can use the OrderBy
keyword to sort the query results when we:
- Append the
OrderBy
keyword to the method name. - Append the property ...
Get Spring Data now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.