hibernate中的java更改日期格式条件查询?
我正在使用下面的查询显示我的测试名称和日期。现在我的日期格式是2014-02-27 17:26:49.0
,但我需要以2014-02-27
格式显示。如何修改对此的查询
Session ses = sessionFactory.getCurentSession();
Criteria c = ses.createCriteria(user.class);
c.add(Restrictions.eq("id", uid));
c.add(Restrictions.eq("name", uname));
ProjectionList pl = Projections.projectionList();
pl.add(Projections.property("testid"));
pl.add(Projections.property("date"));
c.setProjection(Projections.distinct(pl));
List<String> list = c.list();
# 1 楼答案
上面的代码不正确。它选择两个字段,您假设它返回一个
List<String>
。这是不可能的。列表中的每个元素都是一个对象数组,包含两个元素:testid和date。date元素的类型将与实体中的date字段相同(我希望是java.util.Date
)因此,要使用特定的格式显示查询结果,可以使用以下内容:
# 2 楼答案
# 3 楼答案
试试这个
输出:
# 4 楼答案