如何在Spring数据中编写"Count By"方法名称查询

Hap*_*r86 13 spring-data

所以我知道我可以编写如下所示的接口,Spring Data会自动为我生成必要的数据库访问内容.现在我要做的是添加一个新的方法名称,它将计算符合一组条件的实体数量.

public interface EventRegistrationRepository extends JpaRepository<EventRegistration, String>
{    
    List<EventRegistration> findByUser_EmailAddress(String email);

    int countByEvent_Code(String eventCode);
}
Run Code Online (Sandbox Code Playgroud)

截至目前,countBy方法导致此错误:

Caused by: org.springframework.data.mapping.PropertyReferenceException: No property count found for type com.brazencareerist.brazenconnect.model.relational.EventRegistration
Run Code Online (Sandbox Code Playgroud)

我正在尝试做什么的正确语法是什么?

Oli*_*ohm 16

这与刚刚发布的 Spring Data JPA 1.4.0.M1一样有效.

  • 太棒了,谢谢奥利弗.Spring Data摇滚! (2认同)