Spring MVC填充@RequestParam Map< String,String> [英] Spring MVC populate @RequestParam Map<String, String>
本文介绍了Spring MVC填充@RequestParam Map< String,String>的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我的Spring MVC @Controller中具有以下方法:
I have the following method in my Spring MVC @Controller :
@RequestMapping(method = RequestMethod.GET)
public String testUrl(@RequestParam(value="test") Map<String, String> test) {
(...)
}
我这样称呼它:
http://myUrl?test[A]=ABC&test[B]=DEF
但是测试" RequestParam变量始终为空
However the "test" RequestParam variable is always null
我该怎么做才能填充测试"变量?
What do I have to do in order to populate "test" variable ?
推荐答案
如果方法参数是Map或MultiValueMap,但未指定参数名称,则将使用所有请求参数名称和值填充map参数.
If the method parameter is Map or MultiValueMap and a parameter name is not specified, then the map parameter is populated with all request parameter names and values.
所以您将像这样更改定义.
So you would change your definition like this.
@RequestMapping(method = RequestMethod.GET)
public String testUrl(@RequestParam Map<String, String> parameters)
{
(...)
}
在参数中,如果您调用了网址 http://myUrl?A = ABC& B = DEF
And in your parameters if you called the url http://myUrl?A=ABC&B=DEF
您将拥有自己的方法
parameters.get("A");
parameters.get("B");
这篇关于Spring MVC填充@RequestParam Map< String,String>的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文