首先導入三個jackjson jar包,下載地址:
http://download.csdn.net/detail/u011403655/8557305java
在springmvc配置文件中加入spring
<mvc:annotation-driven></mvc:annotation-driven>
json
@ResponseBody
@ResponseBody @RequestMapping("/testJson") public User getJson() { User user = new User("elin", "elin@e-lin.me", "12345", new Date()); return user; }
@ResponseBody @RequestMapping("/testJson") public List<User> getJson() { User user1 = new User("elin", "elin@e-lin.me", "12345", new Date()); User user2 = new User("tom", "tom@e-lin.me", "2323232", new Date()); List<User> list = new ArrayList<User>(); list.add(user1); list.add(user2); return list; }
若是報 406錯誤,描述爲
The resource identified by this request is only capable of generating responses with characteristics not acceptable according to the request 「accept」 headers ().ruby
由於沒有把jar包導入WEB-INF/lib 中,手動複製到這個文件夾下便可markdown