跳至正文
Wener Notes

QueryDSL

约 1 分钟阅读
标签:DSL

子查询

java
BooleanExpression exp = invoice.supplier.number.in(new JPASubQuery()
    .from(company)
    .where(company.active.isTrue())
    .list(company.nu‌​mber));

直接使用 Entity 类创建 PathBuilder

java
// entityClass is the entity type, not the Q-type
Class<?> entityClass = Class.forName(...)
// "entity" is the variable name of the path
PathBuilder<?> entityPath = new PathBuilder(entityClass, "entity");
// use getString to get a String path
Predicate predicate = entityPath.getString("property").like("a%");

使用 Map 创建 Predicate

java
// 也可以使用 BooleanBuilder
BooleanExpression expr = null;
for ( int i = 0; i < associations.length; i++ ){
    BooleanExpression innerExpr =
        documentExternalAssocEntity.associationtype.eq(associations[i].getKey())
            .and(documentExternalAssocEntity.associationvalue.eq(associations[i].getValue()))
    if (expr == null) {
        expr = innerExpr;
    } else {
        expr = expr.or(innerExpr);
    }
}

关联信息

反向链接、本文链接的其他页面和外部资料。

参考资料

GitHub1 条
最近更新commit 11c95a7编辑