我以这种方式从表单发送一些参数:
myparam[0] : 'myValue1'
myparam[1] : 'myValue2'
myparam[2] : 'myValue3'
otherParam : 'otherValue'
anotherParam : 'anotherValue'
...
我知道我可以通过添加类似的参数来获取控制器方法中的所有参数
public String controllerMethod(@RequestParam Map<String, String> params){
....
}
我想将参数 myParam[] (不是其他参数)绑定到列表或数组(任何保持索引顺序的东西),所以我尝试使用如下语法:
public String controllerMethod(@RequestParam(value="myParam") List<String> myParams){
....
}
and
public String controllerMethod(@RequestParam(value="myParam") String[] myParams){
....
}
但它们都没有绑定 myParams。即使我向地图添加值,它也无法绑定参数:
public String controllerMethod(@RequestParam(value="myParam") Map<String, String> params){
....
}
是否有任何语法可以将某些参数绑定到列表或数组,而不必创建一个带有列表属性的对象作为 @ModelAttribute ?
Thanks