RequestParam从select选项html表单中获取数组

mam*_*uoc 3 spring-mvc

我试图从html中的多选项框中获取多个值.

我进入我的控制器:

/test?t=1&t=2&t=3
Run Code Online (Sandbox Code Playgroud)

在控制器中,我尝试获取int数组:

@RequestParam(value = "t", required = true) int[] t
Run Code Online (Sandbox Code Playgroud)

但当我使用以下方法检查时:

t.length
Run Code Online (Sandbox Code Playgroud)

我只看到1,这意味着Spring只获得1个参数,但我预计3.任何人都有任何想法?

Joh*_*lly 5

我不认为spring会将参数数组转换为String以外的特定类型,因此您应该尝试以下操作:

@RequestParam(value = "t", required = true) String[] t
Run Code Online (Sandbox Code Playgroud)

然后用于Integer.parseInt()将String转换为int.