开发指南002-前后端信息交互规范-返回类ResponseResult

返回类有两个,一般返回类ResponseResult和分页返回类PageResult,本篇介绍ResponseResult

java 复制代码
public class ResponseResult<T> implements Serializable{
    @Schema(description = "平台-返回结构类型 表明是千里马架构返回体")
    private String flag;
    //1.0
    @Schema(description = "平台-返回结构版本 用于版本兼容")
    private String version="1.0";

    @Schema(description = "平台-返回服务的时间戳")
    private String timestamp;

    @Schema(description = "平台-请求者")
    private String consumer;//请求者 标识发出请求的系统

    @Schema(description = "平台-返回提供服务的名字")
    private String server; //返回该消息的服务

    @Schema(description = "平台-返回提供服务的名字")
    private String path; //返回该消息的服务路径

    @Schema(description = "平台-请求流水")
    private String serialNo;//请求流水

    @Schema(description = "平台-返回码")
    private int retCode;//返回码 IOResultEnum中定义

    @Schema(description = "平台-返回消息")
    private String msg;//返回消息

    @Schema(description = "平台-返回结构信息")
    private T data;//返回结构信息
}

flag用于标识平台服务返回包(有时候前端收到的返回并不是后台服务返回的,而是网关返回)

返回ResponseResult时 底层提供了五种构造方法:

通用

public ResponseResult(String server,String path,String serialNo,String msg,IOResultEnum code,T data)

异常时用

public ResponseResult(String path,RequestInfo requestInfo,Exception e)

错误时用(可以自定义错误消息)

ResponseResult(String path,RequestInfo requestInfo,IOResultEnum code,String msg)

正确时用

public ResponseResult(String path,RequestInfo requestInfo,T data)

无需返回具体数据,只需要正确或错误(看code)

ResponseResult(String path, RequestInfo requestInfo, IOResultEnum code)

相关推荐
疯狂的喵5 小时前
C++编译期多态实现
开发语言·c++·算法
2301_765703145 小时前
C++中的协程编程
开发语言·c++·算法
m0_748708055 小时前
实时数据压缩库
开发语言·c++·算法
lly2024065 小时前
jQuery Mobile 表格
开发语言
惊讶的猫6 小时前
探究StringBuilder和StringBuffer的线程安全问题
java·开发语言
jmxwzy6 小时前
Spring全家桶
java·spring·rpc
Halo_tjn6 小时前
基于封装的专项 知识点
java·前端·python·算法
m0_748233176 小时前
30秒掌握C++核心精髓
开发语言·c++
Fleshy数模6 小时前
从数据获取到突破限制:Python爬虫进阶实战全攻略
java·开发语言
Duang007_7 小时前
【LeetCodeHot100 超详细Agent启发版本】字母异位词分组 (Group Anagrams)
开发语言·javascript·人工智能·python