且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

Spring Mvc提交/删除表中的已检查(选定)记录

更新时间:2023-12-04 21:40:52

听起来像是一个约束性问题。您是否尝试使用Spring的< form:checkbox> 标记而不是< spring:bind> ?它将自动生成复选框属性,并添加一个隐藏字段,Spring使用该字段来确定复选框是开还是关。

Sounds like a binding issue. Have you tried using Spring's <form:checkbox> tag rather than <spring:bind>? It will automatically generate the checkbox attributes as well as adding a hidden field that Spring uses to determine whether the checkbox is 'on' or 'off'.

<form:form action="submitList" method="post" modelAttribute="myObjectForm">
    <table>
        <tbody>
            <c:forEach items="${myObjectForm.myList}" var="row" varStatus="status">
        <tr>
                <td>
                    <form:checkbox path="myList[${status.index}].checkControl"/>
                    </td>
                    <td>${row.name}</td>
                    <td>${row.code}</td>
            </tr>
        </c:forEach>
        </tbody>
    </table>  
    <button type="submit">Submit</button>
</form:form>