在不使用方法参数的情况下,通过spring-data-jpa中的布尔属性进行查询

Mik*_*cki 45 java spring-data spring-data-jpa

是否可以在不使用方法参数的情况下通过Spring Data JPA中的布尔属性进行查询?

基本上我希望这可以在不使用自定义@Query注释的情况下工作:

@Query("SELECT c FROM Entity c WHERE c.enabled = true")
public Iterable<Entity> findAllEnabled();
Run Code Online (Sandbox Code Playgroud)

ora*_*oat 105

JPA库部分创建查询有以下几种方法.

True    findByActiveTrue()  … where x.active = true
False   findByActiveFalse() … where x.active = false
Run Code Online (Sandbox Code Playgroud)

我的猜测是使用

@Query
public Iterable<Entity> findByEnabledTrue();
Run Code Online (Sandbox Code Playgroud)


meg*_*cio 21

@Queryanotation甚至可以跳过.所以它应该像这样工作:

public Iterable<Entity> findByEnabledTrue();
Run Code Online (Sandbox Code Playgroud)