java - 在 spring-data-jpa 中通过 boolean 属性查询而不使用方法参数

标签 java spring-data spring-data-jpa

是否可以不使用方法参数在 Spring Data JPA 中通过 boolean 属性进行查询?

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

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

最佳答案

JPA repository section查询创建有以下方法。

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

我的猜测是使用

@Query
public Iterable<Entity> findByEnabledTrue();

关于java - 在 spring-data-jpa 中通过 boolean 属性查询而不使用方法参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17600790/

相关文章:

java - 如何在 thymeleaf 中使用列表来使用输入类型?

java - 在 Spring-Boot JPA 和 Java 中使用 @Query 时出现问题

java - 从sqlite数据库中选择日文字符

java - 如果参数不满足则重新启动while循环

java - java中将ArrayList转换为数组的方法

java - 从数据库中删除值-Spring MVC,数据JPA

mysql - 分页在 Spring Boot Native Query 中不起作用

java - Log4j slf4j 不工作

java - 使用 spring-data 数据未持久保存在连接列中

spring - 为什么我用Spring Data MongoDB得到 "No property node found on entity class … to bind constructor parameter to!"