道阻且长,行则将至,走慢一点没关系,不停下就好了.|

Ac_c0mpany丶

园龄:3年7个月粉丝:6关注:3

📂项目
🔖项目
2022-11-25 14:22阅读: 26评论: 0推荐: 0

统一响应对象

package com.kyk.imoocmall.common;

import com.kyk.imoocmall.exception.ImoocMallExceptionEnum;
import lombok.Data;

/**
 * 统一响应对象
 * @FileName imooc-mall
 * @Author keyongkang
 * @Create 2022-11-25-10:47
 */
@Data
public class R<T> {
    // 状态码
    private Integer status;

    // 消息
    private String msg;

    // 数据
    private T data;

    // 定义两个常量
    private static final int OK_CODE = 10000;

    private static final String OK_MSG = "SUCCESS";

    /**
     * 全参构造方法
     * @param status
     * @param msg
     * @param data
     */
    public R(Integer status, String msg, T data) {
        this.status = status;
        this.msg = msg;
        this.data = data;
    }

    /**
     * 两参的构造方法
     * @param status
     * @param msg
     */
    public R(Integer status, String msg) {
        this.status = status;
        this.msg = msg;
    }

    /**
     * 无参构造方法:默认成功
     */
    public R() {
        this(OK_CODE, OK_MSG);
    }

    /**
     * 默认的响应成功
     * @param <T>
     * @return
     */
    public static <T> R<T> success() {
        return new R<>();
    }

    /**
     * 响应成功并返回数据
     * @param data
     * @param <T>
     * @return
     */
    public static <T> R<T> success(T data) {
        R<T> response = new R<>();
        response.setData(data);
        return response;
    }

    /**
     * 响应错误,自定义响应码和消息
     * @param code
     * @param msg
     * @param <T>
     * @return
     */
    public static <T> R<T> error(Integer code, String msg) {

        return new R<>(code, msg);
    }

    /**
     * 响应错误,传进来的是枚举对象
     * @param ex
     * @param <T>
     * @return
     */
    public static <T> R<T> error(ImoocMallExceptionEnum ex) {

        return new R<>(ex.getCode(), ex.getMsg());
    }
}

本文作者:Ac_c0mpany丶

本文链接:https://www.cnblogs.com/keyongkang/p/16925002.html

版权声明:本作品采用知识共享署名-非商业性使用-禁止演绎 2.5 中国大陆许可协议进行许可。

posted @   Ac_c0mpany丶  阅读(26)  评论(0编辑  收藏  举报
点击右上角即可分享
微信分享提示
评论
收藏
关注
推荐
深色
回顶
收起
  1. 1 You Are My Sunshine REOL
You Are My Sunshine - REOL
00:00 / 00:00
An audio error has occurred.

作曲 : Traditional

You are my sunshine

My only sunshine.

You make me happy

When skies are gray.

You'll never know, dear,

How much I love you.

Please don't take my sunshine away

The other night, dear,

When I lay sleeping

I dreamed I held you in my arms.

When I awoke, dear,

I was mistaken

So I hung my head and cried.

You are my sunshine,

My only sunshine.

You make me happy

When skies are gray.

You'll never know, dear,

How much I love you.

Please don't take my sunshine away.

You are my sunshine,

My only sunshine

You make me happy

When skies are gray.

You'll never know, dear

How much I love you

Please don't take my sunshine away

Please don't take my sunshine away.

Please don't take my sunshine away.