Java 所需的字符串参数不存在 Spring MVC
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/39588801/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Required String parameter is not present Spring MVC
提问by kosas
I want to access two different pages in my browser using:
我想使用以下方法在浏览器中访问两个不同的页面:
http://localhost:8080/name?views
and
和
http://localhost:8080/name?uviews
But I'm getting error Required String parameter 'uviews' is not present when I use first url and I get Required String parameter 'views' is not present when I use second one.
但是当我使用第一个 url 时,我收到错误 Required String parameter 'uviews' is not present,当我使用第二个 url 时,我得到 Required String parameter 'views' is not present。
here is my Response body
这是我的响应正文
@ResponseBody
public Object getViewInJson(@RequestParam("views") String views ,@RequestParam("uviews") String uviews) throws IOException{
loader = new AnalyticsLoader();
return loader.AnalyticsLoader(views,uviews);
}
How can access both views and uviews?
如何访问视图和uviews?
采纳答案by Prasanna Kumar H A
Add required=false
attribute to @RequestParam
..Change to
将required=false
属性添加到@RequestParam
..Change to
@RequestParam(required=false,name="views") String view,..
回答by ChiefTwoPencils
Add required=false
to the @RequestParam
notation for both. Or you could decide to explicitly use one, set it to required=false
and set the other as the defaultValue
.
添加required=false
到@RequestParam
符号两种。或者您可以决定明确使用一个,将其required=false
设置为并将另一个设置为defaultValue
.
See the documentationfor further information.
有关更多信息,请参阅文档。
回答by Lyn
please check your spring version, there is a bug in 3.2.3. https://jira.spring.io/browse/SPR-10592
请检查您的 spring 版本,3.2.3 中有一个错误。 https://jira.spring.io/browse/SPR-10592
回答by Patel Romil
I was using Postman
for API hit, Adding required=false
and defalutValue
might be helpful, but required=false
results in NULL Exception
. Then I have Removed the Headers (can Authorization header)
in Postman and its works.
我正在使用Postman
API 命中,添加required=false
并且defalutValue
可能会有所帮助,但required=false
结果是NULL Exception
. 然后我Removed the Headers (can Authorization header)
在邮递员及其作品中。