[英]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.