提出的解决方案: https://stackoverflow.com/a/11138229/1270045 在java中工作正常,但我在kotlin中。 我如何将谓词数组传递给用kotlin编写的条件构建器,该怎么做?
因此,关于用kotlin编写此内容,我可以继续下去:
cq.select(customer).where(predicates.toArray(new Predicate[]{}));
我的示例代码:
val predicates = mutableListOf<Predicate>()
if (XYZ != null) {
val XYZPath = element.get<Long>("XYZ")
predicates.add(criteriaBuilder.equal(XYZPath, XYZ))
}
criteriaQuery.select(element)
.where(criteriaBuilder.or(???))
答案 0 :(得分:2)
感谢marstran为您解决的帮助:
criteriaQuery.select(element)
.where(criteriaBuilder.or(*predicates.toTypedArray()))