forum

Home / DeveloperSection / Forums / Binding a list in @RequestParam

Binding a list in @RequestParam

Anonymous User 2504 16-Dec-2015
I'm sending some parameters from a form in this way:

myparam[0]     : 'myValue1'
myparam[1]     : 'myValue2'
myparam[2]     : 'myValue3'
otherParam     : 'otherValue'
anotherParam   : 'anotherValue' 
...
I know I can get all the params in the controller method by adding a parameter like

public String controllerMethod(@RequestParam Map<String, String> params){
    ....
}
I want to bind the parameters myParam[] (not the other ones) to a list or array (anything that keeps the index order), so I've tried with a syntax like:

public String controllerMethod(@RequestParam(value="myParam") List<String> myParams){
    ....
}
and

public String controllerMethod(@RequestParam(value="myParam") String[] myParams){
    ....
}
but none of them are binding the myParams. Even when I add a value to the map it is not able to bind the params:

public String controllerMethod(@RequestParam(value="myParam") Map<String, String> params){
    ....
}
Is there any syntax to bind some params to a list or array without having to create an object as @ModelAttribute with a list attribute in it?

Updated on 16-Dec-2015
I am a content writter !

Can you answer this question?


Answer

1 Answers

Liked By