spring-mvc.xml:
<beans xmlns:mvc="http://www.springframework.org/schema/mvc" > <mvc:annotation-driven/>
js代码:
$.post("${pageContext.request.contextPath}/getJson",{},function(data){ alert(JSON.stringify(data)); });
java代码:
@RequestMapping("/getJson") @ResponseBody public List<User> getJson(){ List<User> list = new ArrayList<User>(); User user1 = new User(10, "刘德华", 45); User user2 = new User(12, "张学友", 46); list.add(user1); list.add(user2); return list; }
导入jackson的Jar包
时间: 2024-10-09 07:19:22