1、系统常量接口
package com.echo.blog.api; /** * @className SystemConstant * @author Echo * @description 系统常量接口 * @updateTime 2021/12/11 22:31 * @version 1.0 */ public interface SystemConstant { int SYSTEM_SUCCESS = 0000; //返回成功 int SYSTEM_ERROR = 9999; //返回错误 int LOGIN_FAIL = 9991; //登录失败 int NO_LOGIN = 9992; //未登录 int NO_PERMISSION = 9993; //无权限 int PARAM_ERROR = 9994; //参数异常 int REPEAT_LOGIN = 9995; // 重复登录 }
2、系统返回枚举值
package com.echo.blog.api; import lombok.Getter; /** * @className SystemEnum * @author Echo * @description 系统返回枚举值 * @updateTime 2021/12/11 22:28 * @version 1.0 */ @Getter public enum SystemEnum { LOGIN_FAIL(SystemConstant.LOGIN_FAIL,"用户名或密码错误"), NO_LOGIN(SystemConstant.NO_LOGIN,"请先登录"), LOGIN_EXPIRE(SystemConstant.NO_LOGIN,"登录超时请重新登录"), USERNAME_REPEAT(SystemConstant.SYSTEM_ERROR,"用户名已经存在"), REQUEST_FAIL(SystemConstant.SYSTEM_ERROR,"请求失败"), REQUEST_SUCCESS(SystemConstant.SYSTEM_SUCCESS,"请求成功"), NO_PERMISSION(SystemConstant.NO_PERMISSION,"没有操作权限,请联系管理员"), PARAM_ERROR(SystemConstant.PARAM_ERROR,"参数校验失败"), NO_DATA_FOR_ID(SystemConstant.SYSTEM_ERROR,"当前id没有对应的数据"), PARAM_EMPTY_ERROR(SystemConstant.SYSTEM_ERROR,"请求参数不能为空"), REPEAT_LOGIN(SystemConstant.REPEAT_LOGIN,"您的账号重复登录"), CHECKED(SystemConstant.SYSTEM_ERROR,"该项目已经被处理"), JWT_EXPIRE(SystemConstant.SYSTEM_ERROR,"凭证过期"); private int code; private String msg; SystemEnum(int code,String msg){ this.code = code; this.msg = msg; } }
3、系统统一返回类
package com.echo.blog.api; import lombok.Data; import static com.echo.blog.api.SystemEnum.*; /** * @className SystemResult * @author Echo * @description 系统统一返回类 * @updateTime 2021/12/11 22:44 * @version 1.0 */ @Data public class SystemResult<T> { private int code; private String msg; private T data; // 构造方法 private SystemResult(int code, String msg) { this.code = code; this.msg = msg; } private SystemResult(int code, String msg, T data) { this.code = code; this.msg = msg; this.data = data; } /** * @methodName success * @author Echo * @version 1.0 * @description 返回系统默认的状态码 * @updateTime 2021/12/11 22:50 * @return: com.echo.blog.api.SystemResult * @throws */ public static SystemResult success(){ return new SystemResult(REQUEST_SUCCESS.getCode(),REQUEST_SUCCESS.getMsg()); } /** * @methodName success * @author Echo * @param: msg * @version 1.0 * @description 返回自定义状态信息 * @updateTime 2021/12/11 22:51 * @return: com.echo.blog.api.SystemResult * @throws */ public static SystemResult success(String msg){ return new SystemResult(REQUEST_SUCCESS.getCode(),msg); } /** * @methodName success * @author Echo * @param: data * @version 1.0 * @description 返回系统默认状态码以及自定义数据 * @updateTime 2021/12/11 22:52 * @return: com.echo.blog.api.SystemResult * @throws */ public static <T>SystemResult success(T data){ return new SystemResult(REQUEST_SUCCESS.getCode(),REQUEST_SUCCESS.getMsg(),data); } /** * @methodName fail * @author Echo * @version 1.0 * @description 返回系统默认失败状态值及信息 * @updateTime 2021/12/11 22:54 * @return: com.echo.blog.api.SystemResult * @throws */ public static SystemResult fail(){ return new SystemResult(REQUEST_FAIL.getCode(),REQUEST_FAIL.getMsg()); } /** * @methodName fail * @author Echo * @param: msg * @version 1.0 * @description 返回系统默认失败状态值以及自定义信息 * @updateTime 2021/12/11 22:55 * @return: com.echo.blog.api.SystemResult * @throws */ public static SystemResult fail(String msg){ return new SystemResult(REQUEST_FAIL.getCode(),msg); } /** * @methodName fail * @author Echo * @param: code * @param: msg * @version 1.0 * @description 返回系统自定义失败状态值以及信息 * @updateTime 2021/12/11 22:56 * @return: com.echo.blog.api.SystemResult * @throws */ public static SystemResult fail(int code, String msg){ return new SystemResult(code,msg); } }
现项目目录如下: