一、 Feign @SpringQueryMap支持
OpenFeign @QueryMap批注支持将POJO用作GET参数映射。不幸的是,默认的OpenFeign QueryMap注释与Spring不兼容,因为它缺少value属性。
Spring Cloud OpenFeign提供等效的@SpringQueryMap批注,该批注用于将POJO或Map参数注释为查询参数映射。
二、使用步骤
1.api(即微服务rest接口层)
代码如下:
@RestController
@RequestMapping("/demo")
public class DemoController {@Autowiredprivate IDemoMgtService demoMgtService;@GetMapping("/list")public String filterList(Params params) {return demoMgtService.filterList(params);}
}
2.feign(为调用其它微服务接口层定义)
代码如下:
@FeignClient(contextId = "remoteDemoService", value = ServiceNameConstants.DEMO_SERVICE, fallbackFactory = RemoteDemoFallbackFactory.class)
public interface RemoteDemoService
{@GetMapping("/demo/list")public String filterList(@SpringQueryMap Params params, @RequestHeader(SecurityConstants.FROM_SOURCE) String source);
}