【问题标题】:Is there any form to group a conditions in a query method with spring-data jpa?是否有任何形式可以使用 spring-data jpa 对查询方法中的条件进行分组?
【发布时间】:2013-06-19 20:21:42
【问题描述】:
例如结果sql应该是:
SELECT * FROM transaction t WHERE t.type = 4 AND (t.status = 1 OR t.value = 2)
但是在查询方法的方式中,我不知道它必须是怎样的
public List<Transaction> findByTypeAndStatusAndValue(int type, int status, int value);
我不确定上面的代码是否按预期工作。
【问题讨论】:
标签:
java
spring
jpa
spring-data
spring-data-jpa
【解决方案1】:
您始终可以提供自定义查询:
@Query("select t from Transaction t where t.type = ?1 and (t.status = ?2 or t.value = ?3)")
public List<Transaction> findByTypeAndStatusOrValue(int type, int status, int value);