FeignClient接口格式

2024-10-09 08:39:42 浏览数 (1)

FeignClient接口格式 报错信息: {"timestamp":1648015711758,"status":404,"error":"Not Found","message":"No message available","path":"/getDto"}

/order/getDto 完整的地址。

2022-03-23 14:45:40.188 [SimpleAsyncTaskExecutor-1] ERROR [03964e0b1ec5783d,03964e0b1ec5783d] o.s.a.i.SimpleAsyncUncaughtExceptionHandler#handleUncaughtException [line:38] - Unexpected error occurred invoking async method: xxx java.lang.ClassCastException: java.util.LinkedHashMap cannot be cast to XXXDTO

代码语言:javascript复制
//标准写法
@FeignClient(name="order-api")
public interface FeignTestService {

    @GetMapping("/order/getDto")   //url必须要完整
    public ResponseData<OrderDTO> getOrderDto(@RequestParam(value = "orderNo") String orderNo);   //ResponseData后面的泛型带上类型,避免调用方接收需要类型转换

}

@Data
public class ResponseData<T> {

    @AutoDocProperty(value = "返回代码")
    private String resCode;
    @AutoDocProperty(value = "返回消息")
    private String resMsg;
    @AutoDocProperty(value = "返回实体")
    private T data;
    
}


//                LinkedHashMap hashMap = (LinkedHashMap) responseData.getData();
                //json转对象
//                OrderDTO dto = JSON.parseObject(JSON.toJSONString(hashMap), OrderDTO.class);

//正确的接收方法:
                OrderDTO dto = responseData.getData();

0 人点赞