提出的解决方案: 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(???))
最佳答案
感谢 marstran 的帮助解决了这个问题:
criteriaQuery.select(element)
.where(criteriaBuilder.or(*predicates.toTypedArray()))
关于java - 有没有办法将 jpa 谓词数组传递给 KOTLIN 中的 criteriabuilder?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54326037/