Springcloud 之feign调用踩坑
程序员文章站
2022-04-26 10:31:42
...
@RestController
@RequestMapping("/ykt")
public class YktController {
@PostMapping("/queryPermissionByCardNumber/{cardNumber}")
public String queryPermissionByCardNumber(@PathVariable(value = "cardNumber") String cardNumber) {
return yktService.queryPermissionByCardNumber(cardNumber);
}
@PostMapping("/openDoor/{channelList}")
public String openDoor(@PathVariable(value = "channelList") List<String> channelList) {
closeDoor(channelList);
List<String> newList = new ArrayList<>();
for (String str : channelList) {
newList.add(str.replace("-", "$"));
}
return yktService.openDoor(newList);
}
}
服务提供者
@SuppressWarnings("ALL")
@FeignClient(value = "device", fallback = ScheduleDeviceServiceHys.class)
public interface ScheduleDeviceService {
@PostMapping("/ykt/queryPermissionByCardNumber/{cardNumber}")
public String queryPermissionByCardNumber(@PathVariable(value = "cardNumber") String cardNumber);
@PostMapping("/ykt/openDoor/{channelList}")
public String openDoor(@PathVariable(value = "channelList") List<String> channelList);
}
服务消费者
服务消费者接口必须和提供者接口完全相同(其中注解最好不用@RequestMapping)最好明确用@PostMapping或者@GetMapping
另外携带参数时接口中@PathVariable后面须指定value的值,不然会报错
推荐阅读
-
Vue.js 踩坑记之双向绑定
-
nuxt踩坑之Vuex状态树的模块方式使用详解
-
vue踩坑记录之数组定义和赋值问题
-
Angular 4.x+Ionic3踩坑之Ionic 3.x界面传值详解
-
Angular 4.x+Ionic3踩坑之Ionic3.x pop反向传值详解
-
微信公众号支付之坑:调用支付jsapi缺少参数 timeStamp等错误解决方法
-
Element-UI踩坑之Pagination组件的使用
-
跟我学SpringCloud | 第三篇:服务的提供与Feign调用
-
(springCloud-8 Zuul网关路由的基本配置feign实现接口调用)
-
SpringBoot1.x升级SpringBoot2.x踩坑之文件上传大小限制