SpringMVC comment (ResponseBody)

@responseBody

1、

@responseBody annotation object after the action of the controller method returns to the specified format converted by a suitable converter, is written to the response object body region, typically to return JSON or XML data

Data, it should be noted that, after trying to use this annotation processor would not go, but directly to write data to the input stream, his effect is equivalent to specify the format of the data output by the response object.

2、

@RequestMapping ( "/ Login")
  @ResponseBody
  public the User Login (the User User) {
    return User;
  }
  the User Field: userName pwd
  then received reception data: '{ "userName": " xxx", "pwd": "xxx"} '

Effect is equivalent to the following code:
  @RequestMapping ( "/ Login")
  public void Login (the User User, the HttpServletResponse Response) {
    response.getWriter.write (JSONObject.fromObject (User) .toString ());
  }

Released three original articles · won praise 0 · Views 738

Guess you like

Origin blog.csdn.net/CLAYql/article/details/89086376