【问题标题】:Empty parameter in spring cloud feign clientspring cloud feign客户端中的空参数
【发布时间】:2020-01-27 14:07:59
【问题描述】:

2.1.1 版本更新到2.1.2 版本后,spring-cloud-openfeign-core 出现问题。

当我使用空参数执行调用时,它总是将其名称添加到以前不是这种情况的查询字符串中。 2.1.1 中生成的 url 是 http://test.url/endpoint,但在 2.1.2 中它变成了 http://test.url/endpoint?id,最后是 ?id

// request
myFeignClient.myGetRequest(List.of())

// client
@FeignClient(name = "client", url = "http://test.url/")
public interface MyFeignClient {

    @RequestLine("GET /endpoint?id={id}")
    Object get(@Param(value = "id") List<String> id);
}

有什么办法可以去掉空参数名?

【问题讨论】:

    标签: spring-cloud-feign


    【解决方案1】:

    我不希望这会起作用。 Have a look at this

    你应该在客户端 feign 中试试这个:

    @GetMapping("/endpoint")
    @ResponseBody
    Object get(@RequestParam(value = "id", required = false) List<String> id);
    

    服务器:

    @GetMapping("/endpoint")
    Object get(@RequestParam(value = "id", required = false) List<String> id) {
         //...
    }
    

    【讨论】:

      猜你喜欢
      • 2017-01-22
      • 2021-10-22
      • 2016-05-11
      • 2017-11-02
      • 2019-01-26
      • 2020-05-12
      • 2016-07-01
      • 1970-01-01
      • 2016-10-28
      相关资源
      最近更新 更多