我从来没有做过多维数组,但它应该是这样的东西(虽然我没有尝试过,它只是给你一个想法)。在JSP中,你应该设置输入的名称与每个索引,这样的事情:
<c:forEach var="row" items="${days}" varStatus="statusRow">
<c:forEach var="day" items="${row}" varStatus="statusCol">
<input type="text" name="days[${statusRow.index}][${statusCol.index}].title" value="${day.title}"/>
</c:forEach>
</c:forEach>
,并在控制器,你必须准备天变量,这样数组的大小是一样的,你得到了一个来自JSP。因此,您可以使用@ModelAttribute方法来准备数组(该方法将在@RequestMapping方法之前执行)。
@ModelAttribute("days")
public getDays(){
DayInfo[][] days;
//Here you have to instantiate the days to prepare it so it can be filled
//You can load for example the data from the database
return days;
}
@RequestMapping("/yourURL")
public String getFormData(@ModelAttribute("days")DayInfo[][] days){
//Here in days you should have the data from the form overriding
// the one from the database
}
希望这有助于和抱歉,如果有任何错误,虽然我正在努力尝试它。