我是靠谱客的博主 勤劳香菇,这篇文章主要介绍Java基础(十二)GET请求获取可变参数(HTTP Status 400 - Required String parameter 'a' is not present)一.使用注解@RequestParam二.直接写成参数接收即可,现在分享给大家,希望可以做个参考。

 

一.使用注解@RequestParam

 

  •   1.使用
复制代码
1
2
3
4
5
6
7
8
@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.结果:
复制代码
1
2
3
4
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.使用
复制代码
1
2
3
4
5
6
7
8
@RequestMapping("/index") public String index(HttpServletRequest request, HttpServletResponse response,Model model,String a, String b){} 2.即可实现参数可传入或者可不传入 版权声明:本文为博主原创文章,未经博主允许不得转载

 

 

 

 

 

 

 

 

 

 

 

 

最后

以上就是勤劳香菇最近收集整理的关于Java基础(十二)GET请求获取可变参数(HTTP Status 400 - Required String parameter 'a' is not present)一.使用注解@RequestParam二.直接写成参数接收即可的全部内容,更多相关Java基础(十二)GET请求获取可变参数(HTTP内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(39)

评论列表共有 0 条评论

立即
投稿
返回
顶部