@QueryMap在主体中传递参数



我有一个简单的POJO:

class FilterDTO(
open var page: Int = 0,
open var size: Int = 20
)

和一个简单的虚拟客户端:

@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

相关内容

  • 没有找到相关文章

最新更新