I'm trying to catch an array that has been posted to my Java Controller with the code shown below:
@RequestMapping(method=RequestMethod.POST, value="/json/foo.json")
public @ResponseBody Object foo(List fooIds)
{
for (Integer id : fooIds)
{
fooService.delete(id);
}
return null;
}
However I keep getting the following error:
Could not instantiate bean class [java.util.List]: Specified class is an interface
The array I am posting is setup as follows (in PHP):
$array = array(
"fooIds[0]" => 1,
"fooIds[1]" => 2,
"fooIds[2]" => 3,
"fooIds[3]" => 4,
"fooIds[4]" => 5,
);
Originally I tried:
$array = array(1,2,3,4,5);
but that didn't work either.
解决方案
I've got it to working with the following code:
@RequestMapping(method=RequestMethod.POST, value="/json/foo.json")
public @ResponseBody Object foo(@RequestParam("ids") int[] fooIds)
{
for (Integer id : fooIds)
{
fooService.delete(id);
}
return null;
}
The array is then setup like this:
$array = array(
'fooIds' => '1,2,3,4,5',
);