查询dsl加入条件

Querydsl join condition

我在 Spring JPA 中使用 querydsl。我想找到具有两个条件的子项的实体。此代码适用于单一条件(即 any.selected.isTrue())。但是他们不一起工作。这样的查询怎么用querydsl来表达呢?

QSub any = exp.sub.any();
    builder.and(
        any.selected.isTrue().and(any.sub.person.id.eq(user.getId()))));

其中构建器是布尔构建器。

我发现(按照其他帖子的建议)创建子查询解决了问题:

JPQLQuery<Tuple> where = JPAExpressions.select().from(QSub.sub).where(QSub.sub.id.eq(QMain.main.id), QSub.sub.selected.isTrue(), QSub.sub.userId.eq(user.getId()));

"Where" 然后可以作为条件添加到布尔构建器。