码迷,mamicode.com
首页 > 其他好文 > 详细

ResultVM 返回前端实体类

时间:2020-10-31 01:21:33      阅读:20      评论:0      收藏:0      [点我收藏+]

标签:实体类   code   nal   通用   class   lan   zab   状态码   integer   

 * Created by cws
 */
@Data
public class ResultVM implements Serializable {
    private static final long serialVersionUID = 1L;

    public static final Integer CODE = 0;

    private Integer code;

    private String msg;

    private Object result;

    public ResultVM() {

    }

    public ResultVM(Integer code) {
        this.code = code;
    }

    public ResultVM(Integer code, String msg) {
        this.code = code;
        this.msg = msg;
    }

    public ResultVM(Integer code, Object result) {
        this.code = code;
        this.result = result;
    }

    public ResultVM(Integer code, String msg, Object result) {
        this.code = code;
        this.msg = msg;
        this.result = result;
    }

    public ResultVM(Object result) {
        this.result = result;
    }

    public static com.aaa.controller.vm.ResultVM error() {
        return error(500, "未知异常,请联系管理员");
    }

    public static com.aaa.controller.vm.ResultVM error(String msg) {
        return error(500, msg);
    }

    public static com.aaa.controller.vm.ResultVM error(Integer code, String msg) {
        return new com.aaa.controller.vm.ResultVM(code, msg);
    }

    /**
     * 带通用返回数据
     * @param msg
     * @param result
     * @return
     */
    public static com.aaa.controller.vm.ResultVM ok(String msg, Object result) {
        return new com.aaa.controller.vm.ResultVM(CODE, msg, result);
    }

    /**
     * 不带数据
     * @param msg
     * @return
     */
    public static com.aaa.controller.vm.ResultVM ok(String msg) {
        return new com.aaa.controller.vm.ResultVM(CODE, msg);
    }

    /**
     * 带数据
     * @param result
     * @return
     */
    public static com.aaa.controller.vm.ResultVM ok(Object result) {
        return new com.aaa.controller.vm.ResultVM(CODE, result);
    }

    /**
     * 只带状态码
     * @return
     */
    public static com.aaa.controller.vm.ResultVM ok() {
        return new com.aaa.controller.vm.ResultVM(CODE);
    }
}

ResultVM 返回前端实体类

标签:实体类   code   nal   通用   class   lan   zab   状态码   integer   

原文地址:https://www.cnblogs.com/cwshuo/p/13885665.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!