Springboot 全局统一返回结果类

warning: 这篇文章距离上次修改已过627天,其中的内容可能已经有所变动。

非常简单的记录一下此功能的实现

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

/**
 * @author :Buckler
 * @date :Created in 2023/8/10 16:40
 * @description:全局统一返回结果
 */
@Data
@AllArgsConstructor
@NoArgsConstructor
public class HttpResult<T> {
    private int code;
    private String message;
    private T data;

    /**
     * 返回成功结果(没有返回结果)
     *
     * @return 成功
     */
    public static <T> HttpResult<T> success() {
        return new HttpResult<>();
    }

    /**
     * 返回成功结果
     *
     * @param data 数据
     * @return 成功结果
     */
    public static <T> HttpResult<T> success(T data) {
        return new HttpResult<>(200, "success", data);
    }

    /**
     * 返回失败结果
     *
     * @param code    响应状态码
     * @param message 原因
     * @return 失败结果
     */
    public static <T> HttpResult<T> failure(int code, String message) {
        return new HttpResult<>(code, message, null);
    }
}
none
最后修改于:2023年08月17日 16:37

已有 24 条评论

  1. 作者以非凡的视角解读平凡,让文字焕发出别样的光彩。

  2. 作者的才华横溢,让这篇文章成为了一篇不可多得的艺术品。

  3. 文章中的实用建议和操作指南,让读者受益匪浅,值得珍藏。

  4. 隐喻层次丰富,留给读者想象空间。

  5. 故事线完整,伏笔巧妙,结局耐人寻味。

  6. 哈哈哈,写的太好了https://www.lawjida.com/

  7. 《灵犬雪莉:冒险再出发》剧情片高清在线免费观看:https://www.jgz518.com/xingkong/20709.html

  8. 《长空雄鹰》剧情片高清在线免费观看:https://www.jgz518.com/xingkong/159699.html

  9. 《逆天邪神 动态漫画第一季》国产动漫高清在线免费观看:https://www.jgz518.com/xingkong/48530.html

  10. 你的文章让我感受到了正能量,非常棒! https://www.yonboz.com/video/26862.html

  11. 1 1

    555

  12. 你的文章让我感受到了正能量,非常棒! http://www.55baobei.com/bHVhiVQ7CU.html

  13. 你的文章内容非常精彩,让人回味无穷。 http://www.55baobei.com/le0cXqhy6w.html

  14. 《谜证2017》国产剧高清在线免费观看:https://www.jgz518.com/xingkong/35118.html

  15. 《梦里的一千道墙(无删版)》台湾剧高清在线免费观看:https://www.jgz518.com/xingkong/135770.html

  16. 每次看到你的文章,我都觉得时间过得好快。 https://www.yonboz.com/video/95364.html

  17. 《精武门1972》动作片高清在线免费观看:https://www.jgz518.com/xingkong/120168.html

  18. 你的文章充满了创意,真是让人惊喜。 https://www.4006400989.com/qyvideo/16938.html

  19. 你的文章充满了创意,真是让人惊喜。 https://www.4006400989.com/qyvideo/16938.html

  20. 《毒中毒》喜剧片高清在线免费观看:https://www.jgz518.com/xingkong/46298.html

添加新评论