RESTアプリケーションでエンティティを更新できるフォームを作成したいと思います。たとえば、私はUserエンティティwhith usernameとrealnameフィールドを持っています。投稿経由でオブジェクトを送信する
私は私のリクエストメソッドに必要ですが、この
@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個のパラメータを追加する必要があります。それは空想的ではありません。
I`m使用スプリングフォームタグ
------- 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";
}
iはスプリングの形態で
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
はい、それは失敗しましたので、私はそれも可能です質問したいと思った – Fixus
はい、可能です。第1のアプローチは悪く、第2のアプローチは良いです。ポストをトリガーするサンプルHTMLフォームを含め、試してみるときに起こることを説明するために質問を言い換えてみてください。 – skaffman