在spring-data-jpa中通过布尔属性查询而不使用方法参数 [英] Query by Boolean properties in spring-data-jpa without using method parameters

查看:53
本文介绍了在spring-data-jpa中通过布尔属性查询而不使用方法参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

Is it possible to query by Boolean properties in Spring Data JPA without using method parameters?

基本上,我希望此方法不使用自定义@Query注释即可:

Basically I would like this to work without using custom @Query annotation:

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

推荐答案

The JPA repository section query creation has the following methods.

True    findByActiveTrue()  … where x.active = true
False   findByActiveFalse() … where x.active = false

我的猜测是要使用

@Query
public Iterable<Entity> findByEnabledTrue();

这篇关于在spring-data-jpa中通过布尔属性查询而不使用方法参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆