1.

  @ResponseBody注解的作用是将Controller的方法返回的对象通过适当的转换器转换为指定的格式之后,写入到response对象的body区,通常用来返回JSON数据或者是XML数据

  需要注意的呢,在使用此注解之后不会再走视图处理器,而是直接将数据写入到输入流中,他的效果等同于response对象输出指定格式的数据。

 

2.

  @RequestMapping("/login")

  @ResponseBody

  public  User login(User user){

    return user;

  }

  User字段:userName,pwd

  那么在前台接收到的数据为:'{"userName":"xxx","pwd":"xxx"}'

  

  效果等同于如下代码:

  @RequestMapping("/login")

  public  void  login(User user,HttpServletResponse response){

    response.getWriter.write(JSONObject.fromObject(user).toString());

  }

相关文章:

  • 2021-09-07
  • 2022-12-23
  • 2021-07-14
  • 2021-08-13
  • 2021-08-08
  • 2022-01-23
  • 2021-12-20
  • 2022-01-18
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-01-14
  • 2021-05-07
  • 2021-12-24
  • 2021-05-22
  • 2021-08-04
相关资源
相似解决方案