如何在querydsl
中创建函数的别名,以便我可以在ORDER BY
或GROUP BY
语句或子查询中使用它?
我试过这段代码:
StringPath idNiv0s = Expressions.stringPath("idNiv0s");
StringExpression func = Expressions.stringTemplate("replace({0},',','')",
Expressions.stringTemplate("substring_index( {0}, ',' , -2 )", ach.ancestors) );
new JPAQuery(entityManager).from(ach)
.groupBy(idNiv0s)
.orderBy(idNiv0s.desc())
.list(new QCritereItem( func.as(idNiv0s) , idNiv0s.count() ));
我得到了这个例外
java.lang.IllegalArgumentException: Undeclared path 'idNiv0s'.
Add this path as a source to the query to be able to reference it.