您的位置:首页 > Web前端 > JavaScript

controller层响应客户端json数据

2016-07-28 14:40 585 查看
网址:http://www.121ask.com/thread-5543-1.html

@RequestMapping("/getUserList")
public String getUserList(HttpServletResponse response) {
response.setCharacterEncoding("UTF-8");
response.setContentType("application/json");

List<User> userList = getUsers();
Gson gson = new Gson();
String json = gson.toJson(userList);
System.out.println("json---"+json);
PrintWriter out = null;
try {
out = response.getWriter();
out.write(json);
out.flush();
}catch(Exception e) {
e.printStackTrace();
}finally {
if(out != null) {
out.close();
}
}

return "/user/userList";
}

//json数据转换

网址:http://blog.sina.com.cn/s/blog_5920510a01011vu8.html
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: