使用Java Spring接收POST数据 [英] Receiving POST data with Java Spring
本文介绍了使用Java Spring接收POST数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我试图捕获一个使用以下代码发布到我的Java控制器中的数组:
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<Integer> 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
我要发布的数组的设置如下(在PHP中):
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,
);
我最初尝试过:
$array = array(1,2,3,4,5);
但是那也不起作用.
推荐答案
我可以使用以下代码:
@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',
);
这篇关于使用Java Spring接收POST数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文