LWM
//T是泛型标签,代表可以给ResponseBean类型对象传入任何类型的属性值
public class ResponseBean<T> {
    //    要封装的数据
    private T data;
    //    数据状态码,用于程序逻辑判断
    private Integer code;
    // 数据状态信息,用于显示在前端视图上
    private String msg;

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }

    public Integer getCode() {
        return code;
    }

    public void setCode(Integer code) {
        this.code = code;
    }

    public String getMsg() {
        return msg;
    }

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

    //    数据正常封装
    public ResponseBean(T data) {
        super();
        this.data = data;
        this.code = 200;
        this.msg = "正常";
    }

    //数据异常封装
// 此时让data保持null状态,传入程序员自定义异常状态码和状态信息
    public ResponseBean(Integer code, String msg) {
        super();
        this.code = code;
        this.msg = msg;
    }

    //全局异常处理会用到
    public ResponseBean(T data, Integer code, String msg) {
        super();
        this.data = data;
        this.code = code;
        this.msg = msg;
    }


}

 

posted on 2023-07-02 12:46  Lwmm  阅读(204)  评论(0编辑  收藏  举报