我有一個包含函數列表的jsp頁面。在控制器中,我從數據庫中獲取這個列表並將它傳遞給jsp。如何在Spring MVC中將複選框值傳遞給控制器
@RequestMapping(value = "/functionlist", method = RequestMethod.GET)
public ModelAndView functionList(Model model) throws Exception {
ModelAndView mv = new ModelAndView("functionList");
mv.addObject("functionList", getFunctionsFromDB());
return mv;
}
在我的jsp頁面中創建表使用的功能
<table id="table">
<thead>
<tr>
<th></th>
<th>Name</th>
<th>Action</th>
</tr>
</thead>
<tbody>
<c:choose>
<c:when test="${not empty functionList}">
<c:forEach var="function" items="${functionList}">
<tr>
<td><input name="id" value="${function.id}" hidden></td>
<td>${function.name}</td>
<td>
<input type="checkbox" id="${function.id}" value="${function.action}"></td>
</tr>
</c:forEach>
</c:when>
</c:choose>
</tbody>
</table>
<button type="submit" name="save">Save</button>
我也給功能ID來複選框ID這個名單。
我的功能實體是以下
public class Function {
private Integer id;
private String name;
private Boolean action;
...
}
我想按按鈕保存並在控制器得到「/ functionlist /保存」複選框我值列表。
這種情況在這裏描述:https://stackoverflow.com/questions/2060839/spring-mvc-and-checkboxes –