通过示例查询Spring数据-在子句中? [英] Query by Example Spring Data - In Clause?

查看:101
本文介绍了通过示例查询Spring数据-在子句中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

根据Spring Docs,我只能为QBE编写完全匹配的内容. 我只需要精确匹配,但需要一组值(查询的IN子句)之间的匹配.

As per Spring Docs, I can write exact matching only for QBE. I need exact matching only but among a set of values (IN clause of query).

例如

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

使用QBE可以实现这一目标吗?还是我完全走错了路?

Is this somehow achievable with QBE or am I totally down the wrong path?

类似的东西:

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

两全其美?

我真正需要的是基于多个字段的动态查询(可能的组合,例如(1,2,4)中的id,status = open,约会日期<今天) 以及分页和排序. 规范是与本机查询分开的唯一方法吗?

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. Is specification the only way to go apart from native query?

推荐答案

我只需要精确匹配,但需要一组值之间的精确匹配(查询的IN子句).

I need exact matching only but among a set of values (IN clause of query).

因此,您需要除完全匹配之外的其他功能.您可能无法在个人"的ID属性中存储一组ID. QBE显然不是适合该工作的工具.

So you need something other than exact matching. You can't possibly store a set of IDs in the ID property of your Person. QBE is clearly not the right tool for the job.

您可以直接使用规范",标准" API,QueryDSL,动态组成的JPQL查询或任何其他解决方案,但不能使用QBE.

You can use Specifications, the Criteria API directly, QueryDSL, a dynamically composed JPQL query, or whatever other solution, but not QBE.

这篇关于通过示例查询Spring数据-在子句中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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