Spring data jpa - 如何通过方法名称组合多个And和Or
我正在尝试迁移应用程序.我正在从 Hibernate 到 Spring Data Jpa 工作.
I am trying to migrate the application. I am working on from Hibernate to Spring Data Jpa.
虽然 spring data jpa 提供了简单的查询构建方法,但我坚持创建同时使用 And
和 Or 运算符
的查询方法.
Though spring data jpa offers simple methods for query building, I am stuck up in creating query method that uses both And
and Or operator
.
方法名 - findByPlan_PlanTypeInAndSetupStepIsNullOrStepupStepIs(...)
当它转换成查询时,前两个表达式被组合起来,它执行为[(exp1 and exp2) or (exp3)]
.
When it converts into the query, the first two expressions are combined and it executes as [(exp1 and exp2) or (exp3)]
.
而需要的是](exp1) and (exp2 or exp3)]
.
谁能告诉我这是否可以通过 Spring data jpa 实现?
Can anyone please let me know if this is achievable through Spring data jpa?
推荐答案
同意 Oliver 的方法名称冗长且不可读,但是为了论证,您可以通过使用等效性来达到预期的结果
Agree with Oliver on long and unreadable method names, but nevertheless and for the sake of argument, you can achieve desired result by using the equivalency
A / (B / C) <=> (A / B) / (A / C)
A and (B or C) <=> (A and B) or (A and C)
所以在你的情况下它应该看起来像这样:
So in your case it should look something like this:
findByPlan_PlanTypeInAndSetupStepIsNullOrPlan_PlanTypeInAndStepupStepIs(...)
相关文章