我正在测试QueryDSL。 如何将下面的sql转换为QueryDSL代码?
select c.*
,(
select count(*)
from project_category_map m
, project p
where 1=1
and m.category_id = c.category_id
and m.project_id = p.project_id
) as project_count
from category c
答案 0 :(得分:0)
public List<Tuple> tuple(Category category) {
QProjectCategoryMap qProjectCategoryMap = QProjectCategoryMap.projectCategoryMap;
QProject qProject = QProject.qProject;
return
this.queryFactory
.select(this.qCategory,
SQLExpressions
.select(qProject.count())
.from(qProjectCategoryMap)
.join(qProject)
.where(qProjectCategoryMap.categoryId.eq(qCategory.categoryId))
.where(qProject.projectId.eq(qProjectCategoryMap.projectId))
)
.from(this.qCategory)
.fetch();
}