其实就是一个普通的类,然后定义几个static静态方法,这样就直接调用该类的static方法。
package org.ongoal.common; import lombok.Data; import lombok.experimental.Accessors; import lombok.extern.slf4j.Slf4j; import java.io.Serializable; @Data @Slf4j @Accessors(chain = true) public class ResponseResult implements Serializable { private static final long serialVersionUID = 1L; private Integer code; private String msg; private Object data; public static ResponseResult success(int code,String msg,Object data){ ResponseResult responseResult = new ResponseResult(); responseResult.setCode(code).setMsg(msg).setData(data); return responseResult; } public static ResponseResult success(Object data){ ResponseResult responseResult = new ResponseResult(); responseResult.setCode(200).setMsg("").setData(data); return responseResult; } public static ResponseResult success(){ ResponseResult responseResult = new ResponseResult(); responseResult.setCode(200).setMsg("请求成功").setData(null); return responseResult; } public static ResponseResult success(int code,String msg){ ResponseResult responseResult = new ResponseResult(); responseResult.setCode(code).setMsg(msg).setData(null); return responseResult; } public static ResponseResult fail(int code,String msg,Object data){ ResponseResult responseResult = new ResponseResult(); responseResult.setCode(code).setMsg(msg).setData(data); return responseResult; } public static ResponseResult fail(int code,String msg){ ResponseResult responseResult = new ResponseResult(); responseResult.setCode(code).setMsg(msg).setData(null); return responseResult; } public static ResponseResult fail(){ ResponseResult responseResult = new ResponseResult(); responseResult.setCode(-1).setMsg("请求失败").setData(null); return responseResult; } }
标签:返回,code,对象,responseResult,ResponseResult,static,msg,public,统一 From: https://www.cnblogs.com/qwg-/p/18027805