SpringMVC表单对象绑定到@ModelAttribute
支持绑定表单对象
jsp:
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %>
<form:form id="itemForm" action="${pageContext.request.contextPath }/items/editItemSubmit.action" method="post" modelAttribute="items"> <form:input path="id" type="hidden"/> 修改商品信息: <table width="100%" border=1> <tr> <td>商品名称</td> <td><form:input path="name" /></td> </tr> <tr> <td colspan="2" align="center"> <input type="submit" value="提交"/> </td> </tr> </table> </form:form>
controller:
@RequestMapping("/editItemSubmit") public String editItemSubmit(@ModelAttribute Items items,Model model){ itemsService.updateItems(items); System.out.println(items); return "forward:list.action"; }
重点是<form:input/>中的modelAttribute
撸的精尽人亡...