注释 @GetMapping 和 @RequestMapping(method = RequestMethod.GET) 之间的区别

新手上路,请多包涵

@GetMapping@RequestMapping(method = RequestMethod.GET) 有什么区别?

我在一些 Spring Reactive 示例中看到,使用 @GetMapping 代替 @RequestMapping

原文由 nowszy94 发布,翻译遵循 CC BY-SA 4.0 许可协议

阅读 1.1k
2 个回答

@GetMapping 是一个组合注释,充当 @RequestMapping(method = RequestMethod.GET) 的快捷方式。

@GetMapping 是较新的注释。它支持消费

消费选项是:

消耗=“文本/普通”

消耗 = {“text/plain”, “application/*”}

有关更多详细信息,请参阅: GetMapping 注解

或阅读: 请求映射变体

RequestMapping 也支持消费

GetMapping 我们只能在方法级别应用,而 RequestMapping 注释我们可以在类级别和方法级别应用

原文由 dhS 发布,翻译遵循 CC BY-SA 4.0 许可协议

正如你 在这里 看到的:

具体来说, @GetMapping 是一个组合注释,充当 @RequestMapping(method = RequestMethod.GET) 的快捷方式。

@GetMapping@RequestMapping 之间的区别

@GetMapping 支持 consumes 属性,如 @RequestMapping

原文由 Deroude 发布,翻译遵循 CC BY-SA 4.0 许可协议

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题