zoukankan      html  css  js  c++  java
  • Result返回前端实体类

    
    import lombok.Data;
    
    import java.util.HashMap;
    
    /**
     * @author Administrator
     */
    @Data
    public class Result<T> {
    
        private static final long serialVersionUID = -8713837118340960775L;
    
        /** 成功*/
        private static final Integer SUCCESS = 0;
        /** 警告*/
        private static final Integer WARN = 1;
        /** 异常 失败*/
        private static final Integer FAIL = 500;
    
        private Integer code;
    
        private String msg;
    
        private Object data;
        public Result(Integer code) {
            this.code = code;
        }
    
        public Result(Integer code, String msg) {
            this.code = code;
            this.msg = msg;
        }
    
        public Result(Integer code, Object data) {
            this.code = code;
            this.data = data;
        }
    
        public Result(Integer code, String msg, Object data) {
            this.code = code;
            this.msg = msg;
            this.data = data;
        }
    
    
        /**
         * 失败并返回数据
         * @param data
         * @return
         */
        public static Result error(Object data) {
            return new Result(FAIL, data);
        }
    
        /**
         * 警告并返回数据
         * @param data
         * @return
         */
        public static Result warn(Object data) {
            return new Result(WARN, data);
        }
    
        /**
         * 成功并返回数据
         * @param msg
         * @param data
         * @return
         */
        public static Result ok(String msg, Object data) {
            return new Result(SUCCESS, msg, data);
        }
    
        /**
         * 带数据
         * @param data
         * @return
         */
        public static Result ok(Object data) {
            return new Result(SUCCESS,data);
        }
    
        /**
         * 成功返回通用数据
         * @return
         */
        public static Result ok() {
            return new Result(SUCCESS, "操作成功");
        }
    
        public static Result error() {
            return Result.error("");
        }
    }
  • 相关阅读:
    Selenium学习之==>常见面试题
    Selenium学习之==>Switch与SelectApi接口详解
    Selenium学习之==>ActionChainsApi接口详解
    Selenium学习之==>WebDriverApi接口详解
    Selenium学习之==>三种等待方式
    Selenium学习之==>18种定位方式的使用
    avaScript 的基础学习(一)
    前端基础之CSS
    Http协议
    前端基础之html
  • 原文地址:https://www.cnblogs.com/cwshuo/p/13996277.html
Copyright © 2011-2022 走看看