zoukankan      html  css  js  c++  java
  • 规定请求返回类

    import com.example.client.exception.yyException;
    import lombok.Data;

    /**
    * 请求返回类
    */
    @Data
    public class Result<T> {
    private Integer code;
    private String msg;
    private T data;

    public Result() {
    }
    /**
    * 功能:响应成功
    *
    * @param data 响应的数据
    * @return woke.cloud.property.transformat.Result
    * @author Keats
    * @date 2019/11/30 8:54
    */
    public static <T> Result<T> OK(T data){
    return new Result<>(0, "响应成功", data);
    }

    private static Result errorResult;
    /**
    * 功能:返回错误,此错误不可定制,全局唯一。一般是代码出了问题,需要修改代码
    *
    * @param
    * @return Result
    * @author Keats
    * @date 2019/11/30 8:55
    */
    public static Result Error(){
    if(errorResult == null){
    synchronized (Result.class){
    if(errorResult == null){
    synchronized (Result.class){
    errorResult = new Result<>(-1, "未知错误", null);
    }
    }
    }
    }
    return errorResult;
    }

    /**
    * 功能:返回异常,直接甩自定义异常类进来
    *
    * @param e 自定义异常类
    * @param data 数据,如果没有填入 null 即可
    * @return woke.cloud.property.transformat.Result<T>
    * @author Keats
    * @date 2019/11/30 8:55
    */
    public static <T> Result<T> Exception(yyException e, T data){
    return new Result<>(e.getCode(), e.getMsg(), data);
    }
    public Result(Integer code, String msg) {
    this.code = code;
    this.msg = msg;
    }

    /**
    * 功能:为了方便使用,使用静态工厂方法创建对象。如需新的构造方式,请添加对应的静态工厂方法
    *
    * @author Keats
    * @date 2019/11/30 8:56
    */
    public Result(Integer code, String msg, T data) {
    this.code = code;
    this.msg = msg;
    this.data = data;
    }

    }
  • 相关阅读:
    下拉列表实现模糊匹配选择
    Java读取修改Properties文件
    idea2018.2.4的安装激活与热部署插件JRebel的激活方法
    request.getScheme() 使用方法
    Navicat连接mysql8.0.1版本出现1251--Client does not support authentication protocol requested by server的解决
    javascript
    CSS第二节
    HTML+CSS
    mysql
    ubuntu常见错误
  • 原文地址:https://www.cnblogs.com/yangxiaoli/p/12703258.html
Copyright © 2011-2022 走看看