All instances of an entity class with one of the class attributes matching a specified value can be retrieved as follows:
public interface FooRepository extends CrudRepository<Foo, Long> {
List<Foo> findAllByName(String name);
}
Invoking the findAllByName
method results in the JPA query select foo from Foo foo where foo.name = :name
will be executed on the underlying database.
Points to note
name
must be an attribute on the Foo
entity class.find
, get
or read
. Other keywords like select
will not work.