Spring data jpa - 如何通过方法名组合多个And和Or [英] Spring data jpa - How to combine multiple And and Or through method name

查看:61
本文介绍了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 提供了简单的查询构建方法,但我仍然坚持创建同时使用 AndOr 运算符 的查询方法.

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.

MethodName - findByPlan_PlanTypeInAndSetupStepIsNullOrStepupStepIs(...)

MethodName - 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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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