一.使用注解@RequestParam
1.使用
@RequestMapping("/index")
public String index(HttpServletRequest request, HttpServletResponse response,Model model,
@RequestParam String a,
@RequestParam String b){}
2.报错原因:只是传入a,或者只是传入b
3.报错信息:HTTP Status 400 - Required String parameter 'a' is not present
4.分析:@requestParam 不指定任何属性的时候,则默认为参数为必传,只有指定了request=false,则改参数才变为可传和可不传。
5.结果:
@RequestMapping("/index")
public String index(HttpServletRequest request, HttpServletResponse response,Model model,
@RequestParam(value="a",required = false) String a,
@RequestParam (value="b",required = false)String b){}
二.直接写成参数接收即可
1.使用
@RequestMapping("/index")
public String index(HttpServletRequest request, HttpServletResponse response,Model model,String a, String b){}
2.即可实现参数可传入或者可不传入
版权声明:本文为博主原创文章,未经博主允许不得转载