我想从html中的多选择选项框中获取多个值。RequestParam从选择选项html格式获取数组
我得到了我的控制器:
/test?t=1&t=2&t=3
在控制器中,我试图让int数组:
@RequestParam(value = "t", required = true) int[] t
但是,当我检查它使用:
t.length
我只看到1,这意味着Spring只能得到1个参数,但我预计3. 任何人都有任何ID EA?
我想从html中的多选择选项框中获取多个值。RequestParam从选择选项html格式获取数组
我得到了我的控制器:
/test?t=1&t=2&t=3
在控制器中,我试图让int数组:
@RequestParam(value = "t", required = true) int[] t
但是,当我检查它使用:
t.length
我只看到1,这意味着Spring只能得到1个参数,但我预计3. 任何人都有任何ID EA?
我不认为春天将参数数组转换为String以外特定类型的,所以你应该尝试以下方法:
@RequestParam(value = "t", required = true) String[] t
,然后使用Integer.parseInt()
到字符串转换为int。
这与Spring 3.2版本的预期一致。 我有一个方法:
@RequestMapping(value = "/blueprint", method = RequestMethod.GET)
public ModelAndView blueprint(@RequestParam(value = "blueprints", required = false) int[] blueprints)
和使用
http://localhost:9000/blueprint?blueprints=2&blueprints=1
或
http://localhost:9000/nbu-portal-webapp/blueprint?blueprints=1,2
的值被转换为正确的int数组时。
嗯,谢谢工作。从来没有想过春天有限制,嘿嘿 – mamruoc 2012-04-26 06:20:54