查找具有与指定值匹配的属性的实体类的所有实例

可以按如下方式检索具有与指定值匹配的类属性之一的实体类的所有实例:

public interface FooRepository extends CrudRepository<Foo, Long> {
  List<Foo> findAllByName(String name);
}

调用 findAllByName 方法导致 JPA 查询 select foo from Foo foo where foo.name = :name 将在底层数据库上执行。

注意事项

  1. name 必须是 Foo 实体类的属性。
  2. 方法名称必须以 findgetread 开头。像 select 这样的其他关键字将无效。
  3. 我们无法保证退回结果的顺序。