2013-02-06 72 views
2

我有一个spring应用程序,其中包含一个request,用于返回json中的Accounts列表。 Account类有一个Date属性。该属性作为json输出中的unix时间戳返回。在回复中更改日期格式

有没有办法将dateformat更改为预定义的格式,而不是将其作为unix时间戳返回?

@RequestMapping(value = "/userAccounts.json", method = RequestMethod.GET) 
     public @ResponseBody ArrayList<Account> userAccounts() { 
      ArrayList<Account> accounts = accountService.getAllUserAccounts(user); 
      return accounts; 
     } 
+0

请参阅:http://java.dzone.com/articles/how-serialize-javautildate –

+0

我正在寻找一个更全球的解决方案,如:http://stackoverflow.com/questions/9038005/spring-3-1-json-date-format我试过这个解决方案,但没有任何效果。 – heldt

+0

http://stackoverflow.com/questions/6685043/java-ee-what-is-the-correct-layer-for-formatting-domain-model-objects-before-p/6687472#6687472 –

回答