PUT request in Spring MVC

Viewed 32216

I'm trying to write a simple PUT request method in Spring MVC. I got the following:

@RequestMapping(value = "/users/{id}", method = RequestMethod.PUT) 
public @ResponseBody User updateUser(@PathVariable("id") long id, 
                                     String name, 
                                     String email) {
        User user = repository.findOne(id);
        user.setName(name);
        user.setEmail(email);
        System.out.println(user.toString());
        repository.save(user);
        return user; 
} 

Which is obviously wrong, because it returns the following:

User{id=1, name='null', email='null'}

I also tried with @RequestBody annotation, but that also did not help. Any ideas what I'm doing wrong here would be greatly appreciated.

2 Answers
Related