【发布时间】:2012-02-20 17:17:13
【问题描述】:
我正在使用带注释的 Spring 3.1 MVC 代码 (spring-mvc),当我通过 @RequestBody 发送日期对象时,日期显示为数字。 这是我的控制器
@Controller
@RequestMapping("/test")
public class MyController {
@InitBinder
public void initBinder(WebDataBinder binder) {
binder.registerCustomEditor(Date.class,
new CustomDateEditor(new SimpleDateFormat("yyyy-MM-dd"),true));
}
@RequestMapping(value = "/getdate", method = RequestMethod.GET)
public @ResponseBody Date getDate(@RequestParam("dt") Date dt, Model model) {
// dt is properly constructed here..
return new Date();
}
}
当我传入日期时,我能够以格式接收日期。 但是我的浏览器将日期显示为数字
1327682374011
如何让它以我为 webbinder 注册的格式显示日期? 我在某个论坛看到我应该使用jackson mapper,但是我不能改变现有的mapper吗?
【问题讨论】:
标签: java spring spring-mvc