@PostMapping Spring Boot Example

Spring @PostMapping example shows how to use @PostMapping annotation to map HTTP POST requests onto specific handler methods.

@PostMapping Overview

@PostMapping annotation maps HTTP POST requests onto specific handler methods. It is a composed annotation that acts as a shortcut for @RequestMapping(method = RequestMethod.POST).
@PostMapping - shortcut for @RequestMapping(method = RequestMethod.POST)

@PostMapping Example

@PostMapping annotation for mapping HTTP POST requests onto specific handler methods.
In the below example @PostMapping annotation maps "/employees" HTTP POST requests onto specific handler method createEmployee:
@PostMapping("/employees")
public Employee createEmployee(@Valid @RequestBody Employee employee) {
 return employeeRepository.save(employee);
}
Check out a complete example at Spring Boot 2 Hibernate 5 MySQL CRUD REST API Tutorial

Reference


Comments