What is @PostMapping annotation in Spring Web MVC?
What is @PostMapping annotation in Spring Web MVC?
@PostMapping
is a composed annotation that acts as a shortcut for @RequestMapping(method = RequestMethod.POST)
.
@PostMapping annotated methods handle the HTTP POST requests matched with given URI expression.
e.g.
@PostMapping(path = /members, consumes = application/json, produces = application/json)
public void addMember(@RequestBody Member member) {
//code
}
Follows this :example
Hope this helps..!
Spring Framework 4.3 has introduced @PostMapping
annotation.
@PostMapping
is a composed annotation that acts as a shortcut for
@RequestMapping(method = RequestMethod.POST)
Similarly the following annotations are available:
@GetMapping
@PutMapping
@DeleteMapping
@PatchMapping
These annotations can improve the readability of code.
Reference: Spring API documentation.