Skip to content

Instantly share code, notes, and snippets.

@chathurangat
Created January 1, 2018 17:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chathurangat/c15528cc972a448a704dd03f78b9cbbc to your computer and use it in GitHub Desktop.
Save chathurangat/c15528cc972a448a704dd03f78b9cbbc to your computer and use it in GitHub Desktop.
import com.springbootdev.examples.domain.entity.User;
import com.springbootdev.examples.domain.repository.UserRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import static org.springframework.http.MediaType.*;
@RestController
@RequestMapping("/api")
public class UserController
{
@Autowired
private UserRepository userRepository;
@PostMapping(
value = "/users",
consumes = {APPLICATION_JSON_VALUE, APPLICATION_XML_VALUE},
produces = {APPLICATION_JSON_VALUE, APPLICATION_XML_VALUE}
)
public User create(@RequestBody User user)
{
return userRepository.save(user);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment