我想使用如下查询:
from myModel t
where t.f inEqual(1,2,3,4,5)
而不是这个:
from myModel t
where t.f = 1
and t.f = 2
and t.f = 3
and t.f = 4
and t.f = 5
或者也许是这样:
from myModel t
where t.f inGreaterThan(1,2,3,4,5)
而不是这个:
from myModel t
where t.f > 1
and t.f > 2
and t.f > 3
and t.f > 4
and t.f > 5
实际上,inEqual
和inGreaterThan
不是hql中的函数,但我想使用一些东西
最佳答案
您只能对多个“或”执行此操作:
List<String> valueList = new ArrayList<>();
valueList.add("1");valueList.add("2");valueList.add("3");
Query query2 = session.createQuery("from myModel t where t.f in (:values)").setParameterList("values", valueList);
query2.list();
对于多个“与”和大于等,hibernate Criteria 不提供任何 API。如果您想要这样的操作,可以选择 QueryDSL
Query DSL 为此提供了 inAll()
和 goeAll()
等。
关于java - 如何在 hql/hibernate 中的值集中使用 equals?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32623203/