[英]QueryDsl BooleanBuilder: How to create a predicate that compares contents of list?
[英]QueryDSL: How can I create a predicate from a case expression?
我想使用QueryDSL,從返回布爾表達式的case表達式中創建一個Predicate
:
public static Predicate examplePredicate(NumberPath<Integer> typePath, DateTimePath<Date> timestampPath) {
final Expression<Boolean> expr = typePath
.when(0).then(timestampPath.lt(currentTimestamp()))
.when(1).then(timestampPath.goe(currentTimestamp()))
.otherwise(false);
// How can I create a predicate from expr?
}
案例表達式的所有then
子句都返回BooleanExpression
s-實現Predicate
但expr
本身的類型為Expression<Boolean>
。
如何從這樣的case表達式創建Predicate
(可能是BooleanExpression
)?
您可以按以下方式使用CaseBuilder
:
new CaseBuilder()
.when(typePath.intValue().eq(0))
.then(timestampPath.lt(currentTimestamp()))
...
如對原始問題的注釋中所述,這會生成與原始代碼提取所生成的SQL不同的SQL,但會執行所需的功能。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.