一.使用注解@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){}