如何通过方法名称组合多个And和Or

如何通过方法名称组合多个And和Or

本文介绍了Spring Data JPA-如何通过方法名称组合多个And和Or的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试迁移该应用程序.我正在从休眠到Spring Data Jpa 工作.

I am trying to migrate the application. I am working on from Hibernate to Spring Data Jpa.

尽管spring data jpa提供了用于构建查询的简单方法,但我仍然坚持创建同时使用AndOr operator的查询方法.

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

08-04 21:33