【问题标题】:Why does @GetMapping have a 'consumes' attribute?为什么@GetMapping 有一个“消耗”属性?
【发布时间】:2022-01-03 05:20:47
【问题描述】:

在 Spring 框架中,@GetMapping 没有主体。但它有一个“消耗”属性。那么它如何在没有body的情况下使用这个属性呢?

示例:

@GetMapping(value = "/methodA", consumes = "application/json")

【问题讨论】:

标签: java spring-rest


【解决方案1】:

您可以阅读 queryParam/Request HTTP 标头如下:

@GetMapping(value = "{URL}")
public ResponseEntity getMethod(@RequestParam("consumes") String consumes) {
        return ResponseEntity.ok().build();
}

【讨论】:

  • 感谢您的回答。但这不是我的意思。为了更清楚,我在问题中添加了一个示例。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2015-01-22
  • 2023-01-09
  • 1970-01-01
  • 2012-07-11
  • 2012-01-11
  • 1970-01-01
  • 2022-01-16
相关资源
最近更新 更多