What is @PostMapping annotation in Spring Web MVC?

爷,独闯天下 提交于 2020-04-16 03:15:07

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!