我在List
方法中使用Restrictions.in
对象,现在我必须在Restrictions.like
中使用这种情况但是Restrictions.like
不接收List
参数。我怎么解决这个问题?我的代码在底部:
public void setPhones(Set<String> phones) {
this.phones.addAll(phones);
if (!this.phones.isEmpty()) {
aliases.add(new QueryAlias("profile", "profile"));
criterions.add(Restrictions.like("profile.phone", this.phones));
}
}
根据文档(https://docs.jboss.org/hibernate/orm/5.4/javadocs/org/hibernate/criterion/Restrictions.html),您似乎没有直接的方法来进行此操作。
您可以尝试对列表进行迭代,为每个电话添加一个限制。例如:
public void setPhones(Set<String> phones) {
this.phones.addAll(phones);
if (!this.phones.isEmpty()) {
aliases.add(new QueryAlias("profile", "profile"));
for (String phone : phones) {
criterions.add(Restrictions.like("profile.phone", phone));
}
}
}