[英]With QueryDSL, how do you create an expression on a collection where the sub-items match all criteria?
Assume I have an Appointment
table and a Person
table, where an Appointment
has many Person
s. 假设我有一个Appointment
表和一个Person
表,其中Appointment
有很多Person
。
If I wanted to find all Appointments containing at least one Person in my list I would do: 如果我想查找列表中至少包含一个人的所有约会,我将执行以下操作:
Collection<Person> personsList = getInterestedPersons();
BooleanExpresssion expr = appointment.persons.any().in(personsList)
However, what I really want to so is find all Appointments that have ALL the persons in my list. 但是,我真正想要的是找到所有具有我列表中所有人员的约会。
So, how can I construct a BooleanExpression
that will let me filter for all Appointments who have all the Persons? 因此,我该如何构造一个BooleanExpression
,以便让我过滤所有拥有所有Persons的约会?
Note: I must create a BooleanExprsesion, because this is part of a larger generic filter for Appointments, where all the BooleanExpressions get and()ed together. 注意:我必须创建一个BooleanExprsesion,因为这是较大的约会通用过滤器的一部分,所有BooleanExpression都将and()在一起。
Another note, I do not what to find Appointments that have only those Persons, just at least all those in the list. 另一个要注意的是,我没有找到仅具有这些人员( 至少包括列表中所有人员)的约会的内容。
In this case, I guess the following should work: 在这种情况下,我想以下应该起作用:
BooleanBuilder personClause = new BooleanBuilder();
for (Person person : personList)
{
personClause.and(appointment.persons.contains(person));
}
query.where(personClause); // to add the clause
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.