首页 > 代码库 > Spring注解@ResponseBody,@RequestBody

Spring注解@ResponseBody,@RequestBody

@RequestBody 将HTTP请求正文转换为适合的HttpMessageConverter对象。

@ResponseBody 将内容或对象作为 HTTP 响应正文返回,并调用适合HttpMessageConverter的Adapter转换对象,写入输出流。

/**

* @return 返回Person对象到页面

**/

public class Test{

 

      @RequestMapping(value = "http://www.mamicode.com/person/profile/{id}", method = RequestMethod.GET)
      @ResponseBody
       public Person porfile(@PathVariable("id") int uid){
          return new Person(uid, name, status);
       }
}

Spring注解@ResponseBody,@RequestBody