我有一个显示客户列表的 JSP(ArrayList searchResults)。我希望能够选择其中之一,并将其提交给 Spring MVC 控制器。但是,我似乎无法传递所选对象,只能传递它的属性,例如 customerId。我真的需要传递整个对象。
Spring 3.x 中有标准方法可以做到这一点吗?
<c:forEach items="${searchResults}" var="searchResult">
<tr>
<td><c:out value="${searchResult.customerId}" /></td>
<td><c:out value="${searchResult.firstName}" /></td>
<td><c:out value="${searchResult.lastName}" /></td>
<td>
<form method="POST" ACTION="./customercare">
<input type="SUBMIT" value="Select This Customer"/>
<input type="hidden" name ="searchResult" value="${searchResult}"/>
</form>
</td>
</tr>
</c:forEach>
您可以使用春天的form taglib http://static.springsource.org/spring/docs/3.2.x/spring-framework-reference/html/view.html#view-jsp-formtaglib而不是普通的<form>
回发到 Spring MVC 控制器,然后它将值绑定回您指定的模型。
<form:form method="post" action="addContact.html">
<table>
<tr>
<td><form:label path="firstname">First Name</form:label></td>
<td><form:input path="firstname" /></td>
</tr>
...
@RequestMapping(value = "/addContact", method = RequestMethod.POST)
public String addContact(@ModelAttribute("contact")
Contact contact, BindingResult result) {
请参阅这篇文章:http://viralpatel.net/blogs/spring-3-mvc-handling-forms/ http://viralpatel.net/blogs/spring-3-mvc-handling-forms/
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)