Java Spring Boot REST Application Part 2: Queries

In the first part we¬†created a simple REST application to provide access to our employees data. But in most of the cases you also need to query the data. Spring Data Repositories provide a simple way to do so. Let’s take the employees repository interface we’ve created and add an additional method for searching employees by their last name.

package at.grisa.example.rest_example;

import java.util.List;


public interface EmployeeRepository extends PagingAndSortingRepository<Employee, Long> {
 List<Employee> findByLastNameIgnoreCase(@Param("lastName") String lastName);

Spring Data automatically recognizes the method findByLastNameIgnoreCase as a query by parsing the method name.