前后端协议后端统一返回格式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;
    }

}
相关推荐
老华带你飞1 小时前
动物救助|流浪狗救助|基于Springboot+vue的流浪狗救助平台设计与实现(源码+数据库+文档)
java·数据库·vue.js·spring boot·论文·毕设·流浪动物救助平台
Hernon1 小时前
微服务架构设计:从零打造互联网车贷系统 —— 业务背景与架构蓝图
java·微服务·架构·微服务架构设计
952361 小时前
二叉平衡树
java·数据结构·学习·算法
Vic101011 小时前
Java正则表达式性能优化指南:编译开销、类加载与线程安全深度解析
java·性能优化·正则表达式
小二·1 小时前
Spring框架入门:代理模式详解
java·spring·代理模式
Rock_yzh1 小时前
LeetCode算法刷题——53. 最大子数组和
java·数据结构·c++·算法·leetcode·职场和发展·动态规划
简单的话*1 小时前
Logback 日志按月归档并保留 180 天,超期自动清理的配置实践
java·前端·python
m***56721 小时前
在Nginx上配置并开启WebDAV服务的完整指南
java·运维·nginx
Mr.朱鹏1 小时前
RocketMQ可视化监控与管理
java·spring boot·spring·spring cloud·maven·intellij-idea·rocketmq
带刺的坐椅2 小时前
Solon AI 开发学习9 - chat - 聊天会话(对话)的记忆与持久化
java·ai·llm·openai·solon·mcp