我不知道要完美地构建我的问题,但是我试图从html多行表格中获取数据而我不想使用绑定对象而我不希望有很多@RequestParam
参数我的请求处理方法。我希望表单提交返回一个int数组,但我收到以下错误HTTP Status 400 - Required int[] parameter 'department' is not present
。我尝试用这样的方式编写表单就像这样:
<form action="processForm" method="POST">
<select name="department[]">
<option value="NONE">---SELECT---</option>
<c:forEach items="${departments}" var="department">
<option value="${department.getId()}">${department.getName()}</option>
</c:forEach>
</select>
<select name="department[]">
<option value="NONE">---SELECT---</option>
<c:forEach items="${departments}" var="department">
<option value="${department.getId()}">${department.getName()}</option>
</c:forEach>
</select>
<select name="department[]">
<option value="NONE">---SELECT---</option>
<c:forEach items="${departments}" var="department">
<option value="${department.getId()}">${department.getName()}</option>
</c:forEach>
</select>
<select name="department[]">
<option value="NONE">---SELECT---</option>
<c:forEach items="${departments}" var="department">
<option value="${department.getId()}">${department.getName()}</option>
</c:forEach>
</select>
</form>
我的控制器请求映射方法如下
@Request(value = "/form",nethod = RequestMethod.GET)
public String renderForm(){
return "form"
}
@Request(value = "processForm", method = RequestMethod.POST)
public String processForm(@RequestParam("department") int [] department){
for (int i=0;i<department.lenth;i++){
System.out.println(department[i]);
}
}
提前感谢你。
答案 0 :(得分:0)
将@RequestParam
更改为@RequestParam("department[]")
@Request(value = "processForm", method = RequestMethod.POST)
public String processForm(@RequestParam("department[]") int [] department){
for (int i=0;i<department.lenth;i++){
System.out.println(department[i]);
}
}