我的 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 变量始终为空
我必须做什么才能填充“测试”变量?
原文由 Christos Loupassakis 发布,翻译遵循 CC BY-SA 4.0 许可协议
如此处详述 https://docs.spring.io/spring/docs/current/javadoc-api/org/springframework/web/bind/annotation/RequestParam.html
如果方法参数是 Map 或 MultiValueMap 并且未指定参数名称,则使用所有请求参数名称和值填充 map 参数。
所以你会像这样改变你的定义。
在你的参数中,如果你调用了 url http://myUrl?A=ABC&B=DEF
你会在你的方法