您当前的位置: 首页 >  服务器

梁云亮

暂无认证

  • 2浏览

    0关注

    1211博文

    0收益

  • 0浏览

    0点赞

    0打赏

    0留言

私信
关注
热门博文

【精品】服务器端返回统一格式的数据

梁云亮 发布时间:2019-11-20 13:33:43 ,浏览量:2

封装服务器端返回的结果
/**
 * 封装服务器端返回的结果
 *
 * @author hecai
 */
@Getter
@ToString
public class Result {
    /**
     * 请求响应状态码
     */
    private int code;
    /**
     * 请求结果描述信息
     */
    private String msg;
    /**
     * 请求结果数据
     */
    private Object data;

    protected Result(int code, String msg, Object data) {
        this.code = code;
        this.msg = msg;
        this.data = data;
    }

    public Result setCode(int code) {
        this.code = code;
        return this;
    }

    public Result setMsg(String msg) {
        this.msg = msg;
        return this;
    }

    public Result setData(Object data) {
        this.data = data;
        return this;
    }

    /**
     * 将key-value形式的成对出现的参数转换为JSON
     * @param objs
     * @return
     */
    public Result setData(Object... objs) {
        if (objs.length % 2 != 0) {
            throw new RuntimeException("参数个数不对");
        }
        for (int i = 0; i             
关注
打赏
1665409997
查看更多评论
0.0387s