I want to make a form in which I can update my entity in my REST application. For example I have a User entity whith username and realname fields.
Do I need in my request method do something like this
@RequestMapping(value = "/admin/user/update", method = RequestMethod.POST)
public String updateHouse(@RequestBody String username, @RequestBody String realname, Model model)
??
I would prefer to make something like this
@RequestMapping(value = "/admin/house/update", method = RequestMethod.POST)
public String updateHouse(@RequestBody User user, Model model)
I mean that I want to send an object not every field. If i`ll have 20 fields in my entity I would have to add 20 params to my method. Thats not to fancy.
I`m using spring form tag
——- UPDATE
thanks for response. below diffrent entity but real case scenario that i`m trying to start
html code
<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>
controller method
@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";
}
and i receive
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 ().
You don’t need
@RequestBodyhere. Spring will automatically bind the form fields to theHouseclass without it, i.e.