use*_*347 5 java hibernate criteria date-formatting
这段代码给我一个日期时间和计数两个项目的列表.但我需要按时间分组,没有时间.
任何人都可以给我一个线索如何做到这一点?谢谢!
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();
Run Code Online (Sandbox Code Playgroud)
结果:
2013-04-27 11:08:00.0 | 32
2013-04-27 11:10:00.0 | 五
2013-04-28 15:03:27.0 | 12
我需要:
2013-04-27 | 37
2013-04-28 | 12
sku*_*sel 13
您可能会发现Projections#sqlGroupProjection方法很有用.它可以让你使用一个SQL函数date()提取Date形成DateTime列.基本上,而不是打电话
projectionList.add(Projections.groupProperty("dateCreated"));
Run Code Online (Sandbox Code Playgroud)
使用
projectionList.add(Projections.sqlGroupProjection("date(dateCreated) as createdDate", "createdDate", new String[] { "createdDate" }, new Type[] { StandardBasicTypes.DATE }));
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
7269 次 |
| 最近记录: |