鹿岛建设 网站,百度收录网站名,建设假网站,包头seo排名Feign远程调用响应结果格式
public class ResultT {/*** 响应码#xff0c;200为成功*/private Integer code;/*** 响应信息*/private String message;/*** 响应的具体对象*/private T data;
}自定义Feign解码器
Component // 注入Spring的IOC容器中#xff0c;所有…Feign远程调用响应结果格式
public class ResultT {/*** 响应码200为成功*/private Integer code;/*** 响应信息*/private String message;/*** 响应的具体对象*/private T data;
}自定义Feign解码器
Component // 注入Spring的IOC容器中所有的Feign远程调用响应生效
public class FeignResultDecoder implements Decoder {Overridepublic Object decode(Response response, Type type) throws IOException, DecodeException, FeignException {if (response.body() null) {throw new DecodeException(response.status(), 未返回正确的数据, response.request());}String bodyStr Util.toString(response.body().asReader(Util.UTF_8));// TODO 进行转换jackson提供json2obj方法实现Result转换Result result (Result) JsonUtil.json2obj(bodyStr, type);// TODO 最终响应结果为Result中的泛型对象return result.data;}}