OrderAddClient.java @FeignClient(value = "order-add",fallback = OrderAddClientFallBack.class) public interface OrderAddClient { //对于post请求 默认发送body参数 一个方法只能有一个body参数 @PostMapping("order/add") public ResultVO addOrder(Order order, @RequestParam("str")String str); //虽然这里是用get方法 但是如果没有加RequestParam,会人为orderId是以请求体的方式传参,get方法会被强转了post方法传参 @GetMapping("order/get") public Order getOrder(@RequestParam("orderId") String orderId); }
OrderAddClientFallBack.java
@Component public class OrderAddClientFallBack implements OrderAddClient { @Override public ResultVO addOrder(Order order, String str) { System.out.println("addorder的降级"); return ResultVO.success("addorder的降级",null); } @Override public Order getOrder(String orderId) { System.out.println("getorder的降级"); return new Order(); } }