QueryDSL
约 1 分钟阅读
标签:DSL
- querydsl/querydslGitHubquerydsl/querydslquerydsl/querydsl · Apache-2.0, Java · Unified Queries for Java笔记:QueryDSL
- Apache-2.0, Java
- Unified Queries for Java
子查询
BooleanExpression exp = invoice.supplier.number.in(new JPASubQuery()
.from(company)
.where(company.active.isTrue())
.list(company.number));直接使用 Entity 类创建 PathBuilder
// 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
// 也可以使用 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 条
- querydsl/querydslgithub.com/querydsl/querydsl