Binding a list in @RequestParam
Or you could just do it that way:
public String controllerMethod(@RequestParam(value="myParam[]") String[] myParams){
....
}
That works for example for forms like this:
<input type="checkbox" name="myParam[]" value="myVal1" />
<input type="checkbox" name="myParam[]" value="myVal2" />
This is the simplest solution :)
Arrays in @RequestParam
are used for binding several parameters of the same name:
myparam=myValue1&myparam=myValue2&myparam=myValue3
If you need to bind @ModelAttribute
-style indexed parameters, I guess you need @ModelAttribute
anyway.
Subscribing what basil said in a comment to the question itself, if method = RequestMethod.GET
you can use @RequestParam List<String> groupVal
.
Then calling the service with the list of params is as simple as:
API_URL?groupVal=kkk,ccc,mmm
Just complementing what Donal Fellows said, you can use List with @RequestParam
public String controllerMethod(@RequestParam(value="myParam") List<ObjectToParse> myParam){
....
}
Hope it helps!