diff --git a/src/main/java/com/common/Result.java b/src/main/java/com/common/Result.java new file mode 100644 index 0000000..fa6234f --- /dev/null +++ b/src/main/java/com/common/Result.java @@ -0,0 +1,66 @@ +package com.example.common; + +public class Result { + private String code; + private String msg; + private T data; + + private Result(T data) { + this.data = data; + } + + public Result() { + } + + public static Result success() { + Result tResult = new Result<>(); + tResult.setCode(ResultCode.SUCCESS.code); + tResult.setMsg(ResultCode.SUCCESS.msg); + return tResult; + } + + public static Result success(T data) { + Result tResult = new Result<>(data); + tResult.setCode(ResultCode.SUCCESS.code); + tResult.setMsg(ResultCode.SUCCESS.msg); + return tResult; + } + + public static Result error() { + Result tResult = new Result<>(); + tResult.setCode(ResultCode.ERROR.code); + tResult.setMsg(ResultCode.ERROR.msg); + return tResult; + } + + public static Result error(String code, String msg) { + Result tResult = new Result<>(); + tResult.setCode(code); + tResult.setMsg(msg); + return tResult; + } + + public String getCode() { + return code; + } + + public void setCode(String code) { + this.code = code; + } + + public String getMsg() { + return msg; + } + + public void setMsg(String msg) { + this.msg = msg; + } + + public T getData() { + return data; + } + + public void setData(T data) { + this.data = data; + } +}