首页>代码>Swagger的简单案例,适合初级者学习使用>/SwaggerTest/src/main/java/cn/jbit/entity/ResponseBean.java
package cn.jbit.entity;

import java.io.Serializable;

/**
 * @author: xuxiaoqiang
 * @description: Controller通用返回对象
 * @date Created in 2021-05-27 21:31
 * @modified By:
 */
public class ResponseBean implements Serializable {

    private static final long serialVersionUID = 1L;

    /**
     * 成功标记
     */
    private boolean success = true;

    /**
     * 提示信息
     */
    private String msg = "操作成功";

    /**
     * 获取的数据
     */
    private Object data = null;

    /**
     * http状态码
     */
    private int code = 200;

    public ResponseBean() {
    }

    public ResponseBean(boolean success, String msg, Object data, int code) {
        this.success = success;
        this.msg = msg;
        this.data = data;
        this.code = code;
    }

    public boolean isSuccess() {
        return success;
    }

    public void setSuccess(boolean success) {
        this.success = success;
    }

    public String getMsg() {
        return msg;
    }

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

    public Object getData() {
        return data;
    }

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

    public int getCode() {
        return code;
    }

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

    /**
     * 成功返回结果
     */
    public static ResponseBean success() {
        return new ResponseBean();
    }

    /**
     * 成功返回结果
     *
     * @param data 获取的数据
     */
    public static ResponseBean success(Object data) {
        return new ResponseBean(true, "操作成功", data, 200);
    }

    /**
     * 成功返回结果
     *
     * @param data 获取的数据
     * @param msg  提示信息
     */
    public static ResponseBean success(Object data, String msg) {
        return new ResponseBean(true, msg, data, 200);
    }

    /**
     * 失败返回结果
     *
     * @param code 错误码
     */
    public static ResponseBean failed(int code) {
        return new ResponseBean(true, "操作失败", null, code);
    }

    /**
     * 失败返回结果
     *
     * @param code 错误码
     * @param msg  错误信息
     */
    public static ResponseBean failed(int code, String msg) {
        return new ResponseBean(true, msg, null, code);
    }


}
最近下载更多
微信网友_6368711690080256  LV3 2023年2月28日
1203174100  LV1 2023年2月22日
282363  LV1 2022年10月4日
cao1992  LV24 2022年7月18日
yijie110  LV5 2022年4月18日
gy12345  LV6 2022年2月15日
taskmaster  LV6 2022年1月2日
zcl02036716  LV17 2021年12月3日
123854216  LV5 2021年11月24日
hyz419  LV6 2021年9月18日
最近浏览更多
内心向阳  LV4 2023年11月7日
jiemomo  LV12 2023年10月19日
lingtiejing  LV15 2023年10月1日
siximu912  LV10 2023年9月19日
qq573914838  LV5 2023年9月2日
youwuzuichen  LV10 2023年8月14日
空心菜4  LV9 2023年7月16日
8376x123 2023年6月12日
暂无贡献等级
hwbhome 2023年6月4日
暂无贡献等级
wangyz  LV8 2023年5月17日
顶部 客服 微信二维码 底部
>扫描二维码关注最代码为好友扫描二维码关注最代码为好友