【问题标题】:@QueryMap pass parameters in the body@QueryMap 在正文中传递参数
【发布时间】: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


    【解决方案1】:

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

    【讨论】:

      猜你喜欢
      • 2020-05-23
      • 1970-01-01
      • 2020-07-08
      • 1970-01-01
      • 2021-09-22
      • 1970-01-01
      • 1970-01-01
      • 2015-03-22
      • 1970-01-01
      相关资源
      最近更新 更多