我想制作一个表单,可以在其中更新我的REST应用程序中的实体。例如,我有一个用户实体whith用户名和真实姓名字段。通过邮件发送对象
我需要在我的请求方法做这样的事情
@RequestMapping(value = "/admin/user/update", method = RequestMethod.POST)
public String updateHouse(@RequestBody String username, @RequestBody String realname, Model model)
?
我宁愿做这样的事情
@RequestMapping(value = "/admin/house/update", method = RequestMethod.POST)
public String updateHouse(@RequestBody User user, Model model)
我的意思是我要发送的对象不是每一个领域。如果我在我的实体中有20个字段,我将不得不为我的方法添加20个参数。那不是幻想。
我真的使用弹簧形式标签
------- UPDATE
感谢响应。下面指出错误的实体,但实际情况是我真的尝试启动
HTML代码
<c:url var="houseUpdateLink" value="/admin/house/update" />
<form:form method="post" commandName="house" action="${houseUpdateLink}">
<form:input path="house.title" />
<input type="submit" value="send" />
</form:form>
控制器方法
@RequestMapping(value = "/admin/house/update", method = RequestMethod.POST)
public String updateHouse(@RequestBody House house, Model model) {
model.addAttribute("step", 3);
logger.info("test: " + house.getTitle());
return "houseAdmin";
}
,我收到
HTTP Status 415 -
type Status report
message
description The server refused this request because the request entity is in a format not supported by the requested resource for the requested method().
你试过吗? – skaffman 2012-01-04 19:17:57
是的,它失败了,所以我想问是甚至可能的 – Fixus 2012-01-04 19:29:53
是的,这是可能的。第一种方法很糟糕,第二种方法很好。尝试重新描述您的问题以描述您尝试时发生的情况,其中包括触发该帖子的示例HTML表单。 – skaffman 2012-01-04 19:31:01