Query by Example Spring Data - In Clause?

那年仲夏 提交于 2019-12-08 04:04:00

问题


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).

e.g.

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?

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


回答1:


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

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.

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



来源:https://stackoverflow.com/questions/48528066/query-by-example-spring-data-in-clause

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!