Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to pass post array parameter in Spring MVC

Tags:

spring-mvc

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!

like image 604
FurtiveFelon Avatar asked Mar 22 '11 23:03

FurtiveFelon


2 Answers

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 [])

like image 87
kaleemsagard Avatar answered Oct 07 '22 22:10

kaleemsagard


This should work:

@RequestMapping(value="/schedule", method = RequestMethod.POST) public void action(@RequestParam("param") String[] param) 
like image 31
splonk Avatar answered Oct 07 '22 20:10

splonk