spring mvc获取request HttpServletRequest

1.最简单的方式(注解法)

2. 直接的方法,参数中添加(response类似)

package spittr.web;

import static org.springframework.web.bind.annotation.RequestMethod.*;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletRequest;
import org.springframework.beans.factory.annotation.Autowired;

@Controller
@RequestMapping("/")
public class HomeController {
    
   //@Autowired    //方法1
   //private HttpServletRequest req;

  @RequestMapping(method = GET)
// public String home(Model model) { //方法2
public String home(Model model, HttpServletRequest req) { System.out.println(req.getParameter("x")); return "home"; } }

=======================

参: http://www.cnblogs.com/xusir/p/4135419.html

原文地址:https://www.cnblogs.com/zhao1949/p/4844278.html