这段代码为我提供了两个项目Datetime和count的列表。但是我需要按日期将其分组而不需要时间。

谁能给我一个提示怎么做?谢谢!

    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

最佳答案

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

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

采用
projectionList.add(Projections.sqlGroupProjection("date(dateCreated) as createdDate", "createdDate", new String[] { "createdDate" }, new Type[] { StandardBasicTypes.DATE }));

09-10 23:32