有的时候我们需要用到原生的Servlet的一些方法,比如想要获得session就需要用到request的方法,这时我们
只需要在控制器的方法参数定义HttpServletRequest
和
HttpServletResponse
对象
代码示例:
@Controller public class HelloController { @RequestMapping("/hello") public String sayHello(HttpServletRequest request, HttpServletResponse response){ System.out.println(request); System.out.println(response); HttpSession session = request.getSession(); System.out.println(session); return "success"; } }