← All tutorials

GoCareerGo Tutorials

Spring Boot Tutorial

Auto-configuration, REST APIs, JPA, AOP, caching, microservices and Spring Cloud.

@RequestBody & ResponseEntity

@RequestBody deserializes a JSON request body into a Java object; ResponseEntity gives full control over the HTTP response (status, headers, body).

@PostMapping
public ResponseEntity<User> create(@RequestBody User user) {
    User saved = userService.save(user);
    return ResponseEntity.status(HttpStatus.CREATED).body(saved);
}