gpt4 book ai didi

java - 迭代数组以创建 hibernate 条件语句

转载 作者:搜寻专家 更新时间:2023-11-01 01:04:35 25 4
gpt4 key购买 nike

假设我的数组有 3 个整数对象值 = 3,4,5我需要创建如下所示的 hibernate 条件

criteria.add(Restrictions.and(Restrictions.not(Restrictions.eq(
"stepId", new Integer(3))), Restrictions.and(Restrictions
.not(Restrictions.eq("stepId", new Integer(4))), Restrictions
.not(Restrictions.eq("stepId", new Integer(5))))));

上面的条件是手动创建的,我想知道可以通过迭代自动完成

for(Iterator iterator = integerArray.iterator; iterator.hasNext()){
// create the criteria above
}

最佳答案

是的,您可以使用 Disjunction在你的循环中:

Disjunction disjunction = Restrictions.disjunction();
for(Iterator iterator = integerArray.iterator; iterator.hasNext()){
disjunction.add(yourRestriction); //add your restirction here
}
criteria.add(disjunction );

关于java - 迭代数组以创建 hibernate 条件语句,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2046169/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com