@QueryMap 在正文中传递参数

@QueryMap pass parameters in the body

我有一个简单的 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 将其作为查询参数传递?

发现使用 spring-cloud-openfeign 我应该使用 @SpringQueryMap 而不是 @QueryMap,如 docs

中所述