Query methods

In the previous sections, we looked at the CrudRepository and PagingAndSortingRepository interfaces. We looked at the different methods that they provided by default. Spring Data does not stop here. It defines a few patterns that allow you to define custom query methods. In this section, we will look at examples of some of the options Spring Data provides to customize your query methods.

We will start with examples related to finding rows matching specific attribute values. The following example shows different methods in order to search for the User by their name:

    public interface UserRepository     extends PagingAndSortingRepository<User, Long> {      List<User> findByName(String name); List<User> findByName(String name, Sort sort); ...

Get Mastering Spring 5.0 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.