Spring Boot 4 · Controllers and beans
Accept a JSON body
Bind and validate a request body.
@PostMapping
@ResponseStatus(HttpStatus.CREATED)
public User create(@Valid @RequestBody UserRequest request) {
return service.create(request);
}
Official Spring Boot 4 documentation
More controllers and beans commands
- Write a REST controller
- Declare a service
- Define a JPA entity
- Create a repository
- Handle exceptions globally
All controllers and beans commands · Spring Boot 4 cheatsheet