我有一个包含函数列表的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 –