前后端协议后端统一返回格式Result

java 复制代码
/**
 * 后端统一返回结果
 * @param <T>
 */
@Data
public class Result<T> implements Serializable {

    private Integer code; //编码:1成功,0和其它数字为失败
    private String msg; //错误信息
    private T data; //数据

    public static <T> Result<T> success() {
        Result<T> result = new Result<T>();
        result.code = 1;
        return result;
    }

    public static <T> Result<T> success(T object) {
        Result<T> result = new Result<T>();
        result.data = object;
        result.code = 1;
        return result;
    }

    public static <T> Result<T> error(String msg) {
        Result result = new Result();
        result.msg = msg;
        result.code = 0;
        return result;
    }

}
相关推荐
王者之座42 分钟前
java+maven配置yguard的一次实验
java·spring boot·maven
q***61502 小时前
eclipse配置Spring
java·spring·eclipse
Miraitowa_cheems2 小时前
LeetCode算法日记 - Day 106: 两个字符串的最小ASCII删除和
java·数据结构·算法·leetcode·深度优先
q***58192 小时前
Spring全家桶简介
java·后端·spring
武昌库里写JAVA3 小时前
微擎服务器配置要求,微擎云主机多少钱一年?
java·vue.js·spring boot·后端·sql
IUGEI3 小时前
深入解析HTTP长连接原理
java·网络·后端·网络协议·tcp/ip·http·https
q***64973 小时前
头歌答案--爬虫实战
java·前端·爬虫
凌波粒3 小时前
SpringMVC基础教程(4)--Ajax/拦截器/文件上传和下载
java·前端·spring·ajax
汤姆yu3 小时前
基于springboot的电脑商城系统
java·spring boot·后端