I\'m trying to write a simple PUT
request method in Spring MVC. I got the following:
@RequestMapping(value = \"/users/{id}\", method = RequestMe
You can receive name
and email
whith the @RequestBody
annotation:
@RequestMapping(value = "/users/{id}", method = RequestMethod.PUT)
public @ResponseBody User updateUser(@PathVariable("id") long id,
@RequestBody User user) {}
This is a better practice when it comes to REST applications, as your URL becomes more clean and rest-style.
You can even put a @Valid annotation on the User
and validate its properties.
On your postman client, you send the User
as a JSON, on the body of your request, not on the URL. Don't forget that your User
class should have the same fields of your sent JSON object.
See here: