【发布时间】:2015-09-01 11:43:18
【问题描述】:
存储在 MySQL 数据库中的时间戳 '2015-06-15 13:01:48' 在我的 rest api 响应中以 1434369708000 的形式出现。如何处理以使响应也具有相同的格式。我正在使用 Java、Hibernate、Restful WS 和 MySQL。
实体:
private Date CreatedDateTime;
@Column(name = "created_Date_Time", columnDefinition = "TIMESTAMP")
public Date getCreatedDateTime() {
return createdDateTime;
}
public void setCreatedDateTime(Date createdDateTime) {
this.createdDateTime= createdDateTime;
}
JSON 视图:
@JsonView({MessageView.class})
public Date getCreatedDateTime() {
if (device != null) {
return device.getCreatedDateTime();
}
return null;
}
public void setCreatedDateTime(Date CurrentServerUTC) {
if (device != null) {
this.device.getCreatedDateTime(CurrentServerUTC);
}
}
【问题讨论】:
-
你是在使用Jackson进行序列化吗?如果是,哪个版本?
-
是的,使用 Jackson 2.3.3 版