【问题标题】:How to set value to @RequestAttribute in Spring boot using postman or feign client如何在 Spring Boot 中使用 postman 或 feign 客户端为 @RequestAttribute 设置值
【发布时间】:2020-09-25 07:51:53
【问题描述】:

我有这样的方法:

@PostMapping(path = "/workflow-services/{service_id}/tickets",
  consumes = MediaType.APPLICATION_JSON_VALUE, produces = MediaType.APPLICATION_JSON_VALUE)
  public ResponseEntity<TicketIdResponse> createTicket(@PathVariable("service_id") String  serviceId,
  @RequestBody @Validated CreateTicketRequest request, @RequestAttribute Payload payload) {
log.info("Start create ticket [{}]", request);

TicketIdResponse response = ticketService.createTicket(serviceId, request, payload);

log.info("Create ticket response: {}", response);
return ResponseFactory.success(response);

}

那么如何在邮递员或假装客户端中为@RequestAttribute Payload 设置值

非常感谢!

【问题讨论】:

    标签: java spring spring-boot postman


    【解决方案1】:

    @RequestAttribute 注解通常用于检索在服务器端填充但在同一个 HTTP 请求期间填充的数据。例如,如果您使用了拦截器、过滤器或可能的方面来填充“有效负载”属性,那么您应该能够使用 @RequestAttribute 注释来访问它。

    如果您希望从外部客户端(即通过邮递员、curl 或任何其他简单客户端)传递某些东西 - @RequestAttribute 不是前进的方向。

    良好的参考; https://www.baeldung.com/whats-new-in-spring-4-3 https://www.logicbig.com/tutorials/spring-framework/spring-web-mvc/request-attribute.html

    这个SO 帖子也可能有帮助。

    【讨论】:

      猜你喜欢
      • 2020-08-04
      • 2017-01-27
      • 2017-11-02
      • 1970-01-01
      • 2021-01-21
      • 2016-09-14
      • 2020-04-17
      • 2021-04-16
      • 1970-01-01
      相关资源
      最近更新 更多