问题
For what purpose @PostMapping annotation is used in Spring MVC?
回答1:
@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..!
回答2:
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.
来源:https://stackoverflow.com/questions/48745407/what-is-postmapping-annotation-in-spring-web-mvc