How to pass the entire object from jsp to spring controller
I am new to Spring MVC and hope someone can help me figure out this issue. I have jsp like this:
<table border="1">
<tr>
<td width="50">Id</td>
<td width="150">First Name</td>
<td width="150">Last Name</td>
<td width="50">Money</td>
<td width="50"></td>
</tr>
<c:forEach items="${persons}" var="person">
<tr>
<td><c:out value="${person.id}" /></td>
<td><c:out value="${person.firstName}" /></td>开发者_高级运维;
<td><c:out value="${person.lastName}" /></td>
<td><c:out value="${person.money}" /></td>
<td colspan="2"> <a href="<c:url value="removeContact" />">Delete</a></td>
</tr>
</c:forEach>
</table>
When user clicks on the Delete link, I want to pass the entire object (person) to the controller. Can someone please help how would I do that? I will appreciate any help.
This is my controller:
@RequestMapping(value = "/removeContact", method = RequestMethod.GET)
public String removeContact(@ModelAttribute("contact")Person person, BindingResult result) {
System.out.println("============ > "+person.getId());
return "index.jsp";
}
Thanks
First, don't use permit delete operation on GET requests. Use DELETE instead, it's more appropriate. If you use jquery, use the ajax function to submit your data to the controller.
精彩评论