Projections类主要用于帮助Criteria接口完成数据的分组查询和统计功能
List cats
=
session.createCriteria(Cat.
class
) .setProjection(Projections.projectionList() .add(Projections.rowCount()) .add(Projections.avg(
"
weight
"
)) .add(Projections.max(
"
weight
"
)) .add(Projections.min(
"
weight
"
)) .add(Projections.groupProperty(
"
color
"
)) ).addOrder(Order.asc(
"
color
"
)).list();
以上代码相当于select color,count(*),avg(weight),max(weight),min(weight),min(weight) from cat group by color order by color asc;