6

这段代码给了我两个项目日期时间和计数的列表。但我需要按日期分组,没有时间。

谁能给我一个线索怎么做?谢谢!

    Criteria criteria = getSession().createCriteria(Parcel.class);

    ProjectionList projectionList = Projections.projectionList(); 

        projectionList.add(Projections.groupProperty("dateCreated"));
        projectionList.add(Projections.rowCount());

    criteria.setProjection(projectionList);


    List<Object[]> results = criteria.list();

结果:

2013-04-27 11:08:00.0 | 32

2013-04-27 11:10:00.0 | 5

2013-04-28 15:03:27.0 | 12

我需要:

2013-04-27 | 37

2013-04-28 | 12

4

1 回答 1

14

您可能会发现Projections#sqlGroupProjection方法很有用。它允许您使用从列中提取的SQL函数date()。基本上,而不是调用DateDateTime

projectionList.add(Projections.groupProperty("dateCreated"));

采用

projectionList.add(Projections.sqlGroupProjection("date(dateCreated) as createdDate", "createdDate", new String[] { "createdDate" }, new Type[] { StandardBasicTypes.DATE }));
于 2013-05-04T11:50:56.857 回答