我想使用以下
将选择的选项发送到控制器<form action="/save" method="POST" >
<input type="text" name="name"/>
<label>Subjects</label>
<select name="subjects">
<option value="English">English</option>
<option value="Maths">Maths</option>
</select>
<input type="submit" value="Save">
</form>
在发布表格的控制器中,我检查主题列表的大小
@RequestMapping(params={"subjects"}, value = "/save-std", method = RequestMethod.POST)
public String saveStd(@ModelAttribute("std")Student std,
@RequestParam("subjects") List<String> subjects) {
System.out.println("List Size is " + subjects.size() );
return "home";
}
它总是在控制台中显示List Size is 1
,为什么会出现这种情况,或者是获得所有选定选项的更好解决方案?