简体   繁体   English

通过示例查询Spring数据-在子句中?

[英]Query by Example Spring Data - In Clause?

As per Spring Docs, I can write exact matching only for QBE. 根据Spring Docs,我只能编写完全匹配的QBE。 I need exact matching only but among a set of values (IN clause of query). 我只需要精确匹配,但需要一组值(查询的IN子句)。

eg 例如

Person p = new Person();
p.setId(); // need to match among set of ids.
Example.of(p);

Is this somehow achievable with QBE or am I totally down the wrong path? QBE是否可以实现此目标,还是我完全走错了道路?

Something like : 就像是 :

Page<S> findByIdIn(List<Integer> ids, Example<S> e, Pageable p)

best of both worlds? 两全其美?

What I really need, dynamic query based on multiple fields (in possible combinations, say id in (1,2,4), status=open, appointmentDate < today) along with pagination and sorting. 我真正需要的是基于多个字段的动态查询(可能的组合,例如(1,2,4)中的id,status = open,约会date <今天)以及分页和排序。 Is specification the only way to go apart from native query? 规范是脱离本地查询的唯一方法吗?

I need exact matching only but among a set of values (IN clause of query). 我只需要精确匹配,但需要一组值(查询的IN子句)。

So you need something other than exact matching. 因此,除了精确匹配之外,您还需要其他东西。 You can't possibly store a set of IDs in the ID property of your Person. 您可能无法在“个人”的ID属性中存储一组ID。 QBE is clearly not the right tool for the job. QBE显然不是正确的工作工具。

You can use Specifications, the Criteria API directly, QueryDSL, a dynamically composed JPQL query, or whatever other solution, but not QBE. 您可以使用规范,直接使用Criteria API,QueryDSL,动态组成的JPQL查询或任何其他解决方案,但不能使用QBE。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM