【发布时间】:2021-10-16 01:19:10
【问题描述】:
我有一个简单的 POJO:
class FilterDTO(
open var page: Int = 0,
open var size: Int = 20
)
还有一个简单的 Feign 客户端:
@FeignClient(name = "feign-client", url = "\${feign.url.client}")
interface FeignClient{
@GetMapping("get/{id}")
fun getById(@PathVariable("id") id: String, @QueryMap(encoded = true) filter: FilterDTO): Any
}
根据Pull Request #667,我期待这被翻译为:
---> GET http://my.service.com/get/123?page=0&size=20 HTTP/1.1
Content-Length: 64
Content-Type: application/json
---> END HTTP (64-byte body)
<--- HTTP/1.1 200 Ok (807ms)
allow: GET
// ...
{"response": "foo"}
<--- END HTTP (108-byte body)
但我得到的是:
---> GET http://my.service.com/get/123 HTTP/1.1
Content-Length: 64
Content-Type: application/json
{"page":0,"size":2}
---> END HTTP (64-byte body)
<--- HTTP/1.1 405 Method Not Allowed (807ms)
allow: GET
cache-control: no-cache, no-store, max-age=0, must-revalidate
//..
{"timestamp":1628783721302,"status":405,"error":"Method Not Allowed","path":"/get/123"}
<--- END HTTP (108-byte body)
注意 @QueryMap 参数在请求正文中传递,而不是作为 queryString 传递。
它试图调用的端点定义为:
@GetMapping("/get/{id}")
fun getById(
@PathVariable("id")
id: String,
filter: FilterDTO
)
我错过了什么?如何使用@QueryMap 将其作为查询参数传递?
【问题讨论】:
标签: kotlin spring-cloud-feign feign