1

假设我有一个类似以下的 API,其中PersonDto是一个简单的 pojo:

@RequestLine("POST /request/path")
String createPerson(PersonDto dto);

当我调用此 API 时,feign 在请求正文中包含 pojo 的所有属性(到目前为止这是标准且良好的),但我在另一端有一个旧版应用程序,它希望将 POST 数据作为请求参数包含在内。我知道我可以做类似的事情:

@RequestLine("POST /request/path?id={id}&name={name}&...")

但如果我有太多参数,它会变得非常丑陋。

我尝试使用拦截器以编程方式添加参数,RequestTemplate.query但它们最终也都出现在请求正文中。

有什么办法可以在假装中做这样的事情吗?

4

1 回答 1

0

你可以这样使用:

@RequestLine("POST /request/path")
@Headers("Content-Type: application/json")
String createPerson(PersonDto dto);

它需要jdk1.8

于 2017-12-08T10:12:57.357 回答