如何使用列表 限制条件中的参数

问题描述 投票:1回答:1

我在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));
    }
}
java spring hibernate criteria dropwizard
1个回答
0
投票

根据文档(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));
        }
    }
}
© www.soinside.com 2019 - 2024. All rights reserved.