jsp页面代码:
<form:form id="update" modelAttribute="enterpriseNumInfoListSelf" action="${ctx}/enterprise/num/update" method="post"> <c:forEach items="${enterpriseNumInfoSelfList}" var="enterpriseNumInfoSelf" varStatus="status"> <tr> <td>${enterpriseNumInfoSelf.depName}</td> <td>${enterpriseNumInfoSelf.diversionYear}</td> <input type="hidden" name = "enterpriseNumInfoSelfList[${status.index}].safetyNumEnterpriseId" value="${enterpriseNumInfoSelf.safetyNumEnterpriseId}"> <td><input name="enterpriseNumInfoSelfList[${status.index}].gaugeNum" type="text" value="${enterpriseNumInfoSelf.gaugeNum}" disabled="disabled"></td> <td><input name="enterpriseNumInfoSelfList[${status.index}].theRules" type="text" value="${enterpriseNumInfoSelf.theRules}" disabled="disabled"></td> <td><input name="enterpriseNumInfoSelfList[${status.index}].dangerousEnt" type="text" value="${enterpriseNumInfoSelf.dangerousEnt}" disabled="disabled"></td> </tr> </c:forEach> </form:form>
易错点:1.input提交前先将$("input").removeAttr("disabled");否则没有数据提交到后台.
2.input中加disabled是为了在编辑的时候成为可输入框,保存后成为只读状态,其中切换是否只读状态就是将disabled属性内容附为true或false即可;
3.modelAttribute中的对象必须是内部含有list对象集合的外层对象,将之当参数传入后台即可。
4.input中name属性值是modelAttribute中list对象的属性名称;