QueryDsl提供了一种用于汇总从数据库返回的结果的工具,如下所示:
http://www.querydsl.com/static/querydsl/latest/reference/html/ch03s02.html
在该项目中:3.2.4。结果汇总
但是我不知道如何进行三级聚合,也没有找到任何文档,在QueryDSL自动测试类中也没有出现这种情况,这似乎很奇怪。可能,因为这是非常普遍的情况。
这是我想做的事的例子:
DTO的课程:
class DtoLevel1 {
Long id;
List<DtoLevel2> level2;
}
class DtoLevel2 {
Long id;
List<DtoLevel3> level3;
}
class DtoLevel3 {
Long id;
}
查询:
QDtoLevel1 dtoLevel1 = QDtoLevel1.dtoLevel1;
QDtoLevel1 dtoLevel2 = QDtoLevel1.dtoLevel1;
QDtoLevel1 dtoLevel3 = QDtoLevel1.dtoLevel1;
JPAQuery<DtoLevel1> query = new JPAQuery<DtoLevel1>();
// ... query.from,etc
query.transform(
GroupBy.groupBy(dtoLevel1.id).as( // the first level is ok
Projections.constructor(
DtoLevel1.class,dtoLevel1.id,GroupBy.list( // passing grouped items in the first level
Projections.constructor(
DtoLevel2.class,dtoLevel2.id,GroupBy.groupBy(dtoLevel2.id) // the problem is here
.list(
Projections.constructor(DtoLevel3.class,dtoLevel3.id)
)
)
)
)
)
)
在我强调我的问题的那一行中,是一个概念代码,这是我认为应该起作用的方式。这是我需要将属于当前第二级的第三级项目分组的地方,但是我还没有找到一种方法可以仅针对第一级进行分组。