我使用帶註釋的Spring 3.1 MVC代碼(spring-mvc),當我通過@RequestBody發送日期對象時,日期顯示爲數字。 這是我的控制器Spring 3.1 JSON日期格式
@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格式的日期? 我在一些論壇看到我應該使用傑克遜映射器,但不能改變現有的映射器?
謝謝Waqas。我想知道默認的JSON序列化器是如何工作的,因爲我沒有在類路徑中使用jackson jar。可能它不使用傑克遜。 – moh 2012-01-31 16:34:33
@moh爲什麼沒有被接受的答案? – 2013-05-16 12:41:30
@ M.AtifRiaz用戶自12月22日18:27以來沒有活動。 :) – Yubaraj 2015-04-21 11:20:07