index.jsp
<form action="test/some.do">
姓名:<input type="text" name="name"><br/>
年龄:<input type="text" name="age"><br/>
<input type="submit" value="提交">
</form>
一般逐个接收参数要求接收的参数名必须和传参的参数名一致
@Controller
@RequestMapping("/test")
public class MyController {
@RequestMapping(value ={"/some.do"},method = RequestMethod.GET)
public ModelAndView doSome(String name,int age){
……
}
}
使用别名
使用@RequestPara注解的value属性
@RequestMapping(value = "/doparam.do",method = RequestMethod.POST)
public ModelAndView doParameter(String name,
@RequestParam(value = "age",required = false) Integer ageg){
System.out.println("age:"+ageg);
ModelAndView mv=new ModelAndView();
mv.addObject("name",name);
mv.addObject("age",ageg);
mv.setViewName("param");
return mv;
}