SpringMVC请求参数别名设置

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;
    }
上一篇:jsp使用EL表达式取不到后端ModelAndView传来的Object值


下一篇:Springmvc介绍及与Mybatis整合技术详解