Spring Cloud虚拟客户端中的空参数

问题描述 投票:0回答:1

从版本spring-cloud-openfeign-core更新到版本2.1.1后,我对2.1.2感到麻烦。

当我使用空参数执行调用时,它总是将其名称添加到以前不是这种情况的查询字符串中。在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个回答
0
投票

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

并且您应该在客户端伪装中尝试此操作:

@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) {
     //...
}
© www.soinside.com 2019 - 2024. All rights reserved.