gpt4 book ai didi

java - 使用 Jakson 从 Spring 到网络的日期作为时间戳

转载 作者:行者123 更新时间:2023-12-01 11:12:26 26 4
gpt4 key购买 nike

我有Match类和字段Date start。我的目标是以时间戳开始。我使用 Spring、AngularJs 和 jackson 作为 json 转换器。

Spring Controller :

 @RequestMapping(value = "/web2/getMatch", method =RequestMethod.POST)
public @ResponseBody Match getPicksHistory() {
PickDAO pd = new PickDAO();
return pd.getMatch();
}

在 AgularJS Controller 上:

var res = $http.post(urlSer.url+"web2/getMatch");
res.success(function(data, status, headers, config) {
// now returns data.start = "Aug 8, 2015 7:00:00 PM"
// My goal is get as timestamp
});

最佳答案

我认为“时间戳”是指数字时间戳,而不是文本表示。您可以使用自定义ObjectMapper:

@Component
@Primary
public class CustomObjectMapper extends ObjectMapper {
public CustomObjectMapper() {
configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, true);
}
}

关于java - 使用 Jakson 从 Spring 到网络的日期作为时间戳,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32197086/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com