java相关:SpringMvc接收参数方法总结(必看篇)
发布于 2020-6-26|
复制链接
下面小妖就为大家带来一篇SpringMvc接收参数方法总结(必看篇)。小妖觉得挺不错的,现在就分享给大家,也给大家做个参考。一起跟随小妖过来看看吧
接收参数的方式:1.HttpServletRequest方式接收
```java
public ModelAndView test1(HttpServletRequest req){
String userName = req.getParameter("userName");
String password = req.getParameter("password");
System.out.println(userName);
System.out.println(password);
return new ModelAndView("jsp/hello");
}
```
2.@RequestParam方式
```java
public ModelAndView test2(String userName,
@RequestParam("password") String pwd){
System.out.println(userName+","+pwd);
return new ModelAndView("jsp/hello");
}
```