Alex Rivera | Logout

How to pass post array parameter in Spring MVC

Asked 2011-03-22T23:57:18.077
41

I was just wondering how to pass in post parameters such as following exercept from html options, normally i would get a array in language such as php (POST['param'][0]... would work i believe)

url?param=value1&param=value2&param=value3

I tried:

@RequestMapping(value="/schedule", method = RequestMethod.POST)
public void action(String[] param)

But this doesn't work for some reason...

Any ideas would be greatly appreciated!

Edit
Report

1 Answer

55

You can use this:

@RequestMapping(value="/schedule", method = RequestMethod.POST)
public void action(@RequestParam(value = "param[]") String[] paramValues){...}

it will retrieve all values (inside array paramValues) of parameter param (note the attribute value of RequestParam: it ends with [])

answered 2012-12-10T17:22:54.913

Your Answer