直接先贴图(文中的url做了修改):
代码如下:
@FeignClient(name = "Z_KPI_API",url = "${Z.KPI.url:http://11.11.111.111:8080}",fallback = ZApiClientFallback.class)
public Interface ZApiClient{
@PostMapping(path = "a/b",produces = "application/json")
ZQueryResult query( @RequestParam("hostName")String hostName,
@RequestParam(name = "hostType",defaultValue = "ne")String hostType,
@RequestParam("fromTime")String fromTime,
@RequestParam("endTime")String endTime,
@RequestParam(name = "cpllectType",defaultValue = "Zabbix")String collectType,
@RequestParam(name = "history",required = false)Integer history);
}
通过接口文档,需要弄清楚下面几条信息:
1、确定请求方式——post
2、拿到URL:http://11.11.111.111:8080
3、接口的路径:/a/b
4、请求参数
hostName,hostType,fromTime,endTime,collectType,history
5、返回形式:JSON
6、并且需要知道,返回值表示的意思
技术总结:
1、@FeignClient
本次例子,用到的参数是name,url,fallback
2、@RequestParam
本次例子,用到的参数是name,required
可以通过required=false或者true来要求@RequestParam配置的前端参数是否一定要传 ,此处history不一定要传。不传的话会给参数赋值为null。
注意:GET和POST请求传的参数会自动转换赋值到@RequestParam 所注解的变量上
3、@PostMapping
本次例子,用到的参数是path,produces
关于PostMapping和GetMapping有
https://blog.csdn.net/linjpg/article/details/76927075