@ResponseBody修饰String和对象,前台接收的格式
1:String +ResponseBody = 返回值为String
@RequestMapping("/testResponseBody") @ResponseBody public String testResponseBody(){ return "success"; }- <span style="font-weight:normal;"><span style="font-size:18px;">alert---success</span></span>
2:对象+ResponseBody = json对象
@RequestMapping("/testResponseBody2") @ResponseBody public Student testResponseBody2(){ Student s = new Student(); s.setAge(11); s.setName("11"); return s; }alert ---{"age":11,"name":"11"}
3:String +ResponseBody = String
@RequestMapping("/testResponseBody3") @ResponseBody public String testResponseBody3(){ return JSON.toJSONString(SysResult.resultOK()); }alert {"resultcode":0,"resultdesc":""}
字符串可以转换为json对象
4:void+Response
@RequestMapping("/testResponseBody5") public void testResponseBody5(HttpServletResponse response){ response.setContentType("text/html"); PrintWriter out= null; try { out = response.getWriter(); out.println(JSON.toJSONString(SysResult.resultOK())); out.flush(); out.close(); } catch (IOException e) { e.printStackTrace(); } } {"resultcode":0,"resultdesc":""}
转载: http://blog.csdn.net/z_programmer/article/details/76758331