一、介绍
(1)@ResponseBody用于将方法的返回值作为响应体返回给浏览器。
(2)利用ServletAPI也可以实现@ResponseBody的功能
@Controller
public class MyController {
@RequestMapping(value = {"/hello"})
public void hello(HttpServletResponse response) throws IOException {
response.getWriter().print("benjamin");
}
}
二、项目测试
(1)编写Controller类
@Controller
public class MyController {
@RequestMapping(value = {"/hello"})
@ResponseBody
public String hello() throws IOException {
return "hello";
}
}
(2)运行