这篇文章主要介绍了SpringCloud Feign参数问题及解决方法,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友可以参考下
今天遇到使用Feign调用微服务,传递参数时遇到几个问题
1.无参数
以GET方式请求
服务提供者
@RequestMapping("/hello")
public String Hello(){
return "hello,provider";
}
服务消费者
@GetMapping("/hello")
String hello();
2.单个参数
(1)GET——@PathVariable
服务提供者
@GetMapping("/test/{name}")
public String test(@PathVariable String name){
return "hello,"+name;
}
服务消费者
@GetMapping("/test/{name}")
String test(@PathVariable("name") String name);
(2)GET——@RequestParam
服务提供者
@RequestMapping("/test")
public String test(String name){return "hello,"+name;
}