Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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