Difference between the annotations @GetMapping and @RequestMapping(method = RequestMethod.GET)

前端 未结 4 1681
南旧
南旧 2020-12-12 14:19

What\'s the difference between @GetMapping and @RequestMapping(method = RequestMethod.GET)?
I\'ve seen in some Spring Reactive examples, that

4条回答
  •  遥遥无期
    2020-12-12 14:35

    Short answer:

    There is no difference in semantic.

    Specifically, @GetMapping is a composed annotation that acts as a shortcut for @RequestMapping(method = RequestMethod.GET).

    Further reading:

    RequestMapping can be used at class level:

    This annotation can be used both at the class and at the method level. In most cases, at the method level applications will prefer to use one of the HTTP method specific variants @GetMapping, @PostMapping, @PutMapping, @DeleteMapping, or @PatchMapping.

    while GetMapping only applies to method:

    Annotation for mapping HTTP GET requests onto specific handler methods.


    https://docs.spring.io/spring-framework/docs/current/javadoc-api/org/springframework/web/bind/annotation/GetMapping.html

    https://docs.spring.io/spring-framework/docs/current/javadoc-api/org/springframework/web/bind/annotation/RequestMapping.html

提交回复
热议问题