我有一個Contact對象放在請求中,這個對象在 窗體中被修改,然後得到修改的對象。我希望返回的對象與您發送的對象相同,您保留不在表單中的屬性的值。數據綁定彈簧
class Contact{
private String name; // this attributes will be modified
private String lastName;
private Long id;
private Date created; // this atributes will not be modified
// getters and setters ....
}
@RequestMapping(value = "/{id}/edit", method = RequestMethod.GET)
public String updateContact(@PathVariable("id") Long id, Model model) {
Contact c = contactDao.get(id);
model.addAttribute("contact", c);
return "contact/form";
}
@RequestMapping(value = "/{id}/edit", method = RequestMethod.POST)
public String update(@PathVariable("id") Long id, @Valid @ModelAttribute Contact contact, BindingResult result, Model model) {
// The contact I get here I want to keep the original attributes of the
// object sent, and have the changes in the fields shown on the form. is that possible?
return "redirect:/contact";
}
<form:form action="${pageContext.servletContext.contextPath}/tags/create" commandName="contact">
<form:input path="name"/>
<form:errors path="name" cssClass="formError"/>
<form:input path="lastName"/>
</form:form>
我不想使用隱藏字段來維護不會改變
這就是我我在做,而我沒有 – Jhonathan 2012-02-06 22:23:37