Skip to content

Instantly share code, notes, and snippets.

@brunokrebs
Last active March 10, 2016 14:12
Show Gist options
  • Save brunokrebs/c02cd316196dfe6d1c8e to your computer and use it in GitHub Desktop.
Save brunokrebs/c02cd316196dfe6d1c8e to your computer and use it in GitHub Desktop.
package br.com.brunokrebs.rest;
// ... previously added imports ...
import br.com.brunokrebs.repository.UserRepository;
import java.util.List;
@RestController
public class UserRest {
@Autowired
private UserRepository userRepository; // our nice repository implementation
@RequestMapping(path = "/users/", method = RequestMethod.POST)
public User saveUser(@RequestBody User user) {
userRepository.save(user); // using it to persist
return user;
}
@RequestMapping(path = "/users/", method = RequestMethod.GET)
public List<User> getUsers() {
return userRepository.findAll(); // returning all persisted users
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment