Spring data jpa - How to combine multiple And and Or through method name(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(...)
这篇关于Spring data jpa - 如何通过方法名称组合多个And和Or的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:Spring data jpa - 如何通过方法名称组合多个And和Or
基础教程推荐
- 存储 20 位数字的数据类型 2022-01-01
- REST Web 服务返回 415 - 不支持的媒体类型 2022-01-01
- 修改 void 函数的输入参数,然后读取 2022-01-01
- Struts2 URL 无法访问 2022-01-01
- Spring AOP错误无法懒惰地为此建议构建thisJoinPoin 2022-09-13
- 无法复制:“比较方法违反了它的一般约定!" 2022-01-01
- 使用堆栈算法进行括号/括号匹配 2022-01-01
- 问题http://apache.org/xml/features/xinclude测试日志4j 2 2022-01-01
- RabbitMQ:消息保持“未确认"; 2022-01-01
- 如何对 Java Hashmap 中的值求和 2022-01-01
