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
本文介绍在 Spring MVC 中使用两种不同方法来获取 HTTP 请求中的参数:一是通过注解方式,二是直接在方法参数中接收 HttpServletRequest 对象。


3161

被折叠的 条评论
为什么被折叠?



