Feign @QueryMap支持,@SpringQueryMap注解 feign的get传参方式

OpenFeign  @QueryMap 批注支持将POJO用作GET参数映射。不幸的是,默认的OpenFeign @QueryMap注释与Spring不兼容,因为它缺少属性value

Spring Cloud OpenFeign提供等效的@SpringQueryMap注解,该注解用于将POJOMap参数注释为查询参数映射。

例如,Params.java类定义两个属性param1param2

// Params.java
public class Params {
    private String param1;
    private String param2;

    // [Getters and setters omitted for brevity]
}

以下伪装客户端通过使用@SpringQueryMap注解来使用Parma.java类:

@FeignClient("demo")
public class DemoTemplate {

    @GetMapping(path = "/demo")
    String demoEndpoint(@SpringQueryMap Params params);
}

【参考资料】

Spring Cloud中文网官方文档:https://www.springcloud.cc/spring-cloud-greenwich.html

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章