rom*_*rom 0 java syntax jpa hibernate-criteria kotlin
在:https : //stackoverflow.com/a/11138229/1270045 中提出的解决方案 在 java 中工作得很好,但我在 kotlin 中。在这里我如何将谓词数组传递给用 kotlin 编写的标准构建器?
所以它是关于在 kotlin 中写这个我可以传递的:
cq.select(customer).where(predicates.toArray(new Predicate[]{}));
Run Code Online (Sandbox Code Playgroud)
我的示例代码:
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(???))
Run Code Online (Sandbox Code Playgroud)
感谢 marstran 的帮助解决了这个问题:
criteriaQuery.select(element)
.where(criteriaBuilder.or(*predicates.toTypedArray()))
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1169 次 |
| 最近记录: |