简体   繁体   English

如何使用 postman 或 feign 客户端在 Spring 引导中将值设置为 @RequestAttribute

[英]How to set value to @RequestAttribute in Spring boot using postman or feign client

I have method like this:我有这样的方法:

@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);

} }

so how to set value to @RequestAttribute Payload in postman or feign client那么如何在 postman 或假装客户端中将值设置为 @RequestAttribute Payload

Thank you very much!非常感谢!

The @RequestAttribute annotation is usually used to retrieve data that is populated on the server-side but during the same HTTP request. @RequestAttribute 注释通常用于检索在服务器端但在同一 HTTP 请求期间填充的数据。 For example, if you have used an interceptor, filter or possibly an aspect to populate the "payload" attribute then you should be able to access this using the @RequestAttribute annotation.例如,如果您使用了拦截器、过滤器或可能的方面来填充“有效负载”属性,那么您应该能够使用 @RequestAttribute 注释来访问它。

If you are looking to pass something from an external client (ie via postman, curl or any other simple client) - @RequestAttribute is not the way forward.如果您希望从外部客户端传递某些内容(即通过 postman、curl 或任何其他简单客户端)-@RequestAttribute 不是前进的方向。

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

This SO post may also help.这篇SO帖子也可能有所帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM