diff --git a/boot-starter/src/main/java/name/guolanren/autoconfigure/BootStarterAutoConfiguration.java b/boot-starter/src/main/java/name/guolanren/autoconfigure/BootStarterAutoConfiguration.java index 143cd83..bff906d 100644 --- a/boot-starter/src/main/java/name/guolanren/autoconfigure/BootStarterAutoConfiguration.java +++ b/boot-starter/src/main/java/name/guolanren/autoconfigure/BootStarterAutoConfiguration.java @@ -5,6 +5,7 @@ import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; import org.springframework.boot.context.properties.EnableConfigurationProperties; import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.ComponentScan; import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Import; @@ -13,6 +14,7 @@ */ @Configuration @EnableConfigurationProperties(BootStarterProperties.class) +@ComponentScan("name.guolanren") @Import({}) public class BootStarterAutoConfiguration { diff --git a/common/src/main/java/name/guolanren/exception/BusinessException.java b/common/src/main/java/name/guolanren/exception/BusinessException.java new file mode 100644 index 0000000..78b7eef --- /dev/null +++ b/common/src/main/java/name/guolanren/exception/BusinessException.java @@ -0,0 +1,30 @@ +package name.guolanren.exception; + +/** + * @author guolanren + */ +public class BusinessException extends RuntimeException { + + public BusinessException() { + super(); + } + + public BusinessException(String message, Throwable cause, + boolean enableSuppression, + boolean writableStackTrace) { + super(message, cause, enableSuppression, writableStackTrace); + } + + public BusinessException(String message, Throwable cause) { + super(message, cause); + } + + public BusinessException(String message) { + super(message); + } + + public BusinessException(Throwable cause) { + super(cause); + } + +} diff --git a/common/src/main/java/name/guolanren/exception/ExpiredSessionException.java b/common/src/main/java/name/guolanren/exception/ExpiredSessionException.java deleted file mode 100644 index 6fff538..0000000 --- a/common/src/main/java/name/guolanren/exception/ExpiredSessionException.java +++ /dev/null @@ -1,31 +0,0 @@ -package name.guolanren.exception; - -/** - * @author guolanren - */ -public class ExpiredSessionException extends RuntimeException { - - private static final long serialVersionUID = 7484041979257823063L; - - public ExpiredSessionException() { - super(); - } - - public ExpiredSessionException(String message, Throwable cause, - boolean enableSuppression, - boolean writableStackTrace) { - super(message, cause, enableSuppression, writableStackTrace); - } - - public ExpiredSessionException(String message, Throwable cause) { - super(message, cause); - } - - public ExpiredSessionException(String message) { - super(message); - } - - public ExpiredSessionException(Throwable cause) { - super(cause); - } -} diff --git a/common/src/main/java/name/guolanren/exception/GlobalExceptionHandler.java b/common/src/main/java/name/guolanren/exception/GlobalExceptionHandler.java index 3854b6b..2bfaf97 100644 --- a/common/src/main/java/name/guolanren/exception/GlobalExceptionHandler.java +++ b/common/src/main/java/name/guolanren/exception/GlobalExceptionHandler.java @@ -1,7 +1,7 @@ package name.guolanren.exception; -import name.guolanren.http.ResultCode; -import name.guolanren.http.ResultEntity; +import name.guolanren.http.response.ResultCode; +import name.guolanren.http.response.ResultEntity; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.web.bind.annotation.ControllerAdvice; @@ -18,44 +18,33 @@ public class GlobalExceptionHandler { private static final Logger LOG = LoggerFactory.getLogger(GlobalExceptionHandler.class); @ExceptionHandler - public ResultEntity requestHandle(RequestException e) { + public ResultEntity illegalParamHandle(IllegalParamException e) { LOG.error(e.getMessage(), e); - return ResultEntity.faild(ResultCode.REQUEST_FAILD, e.getMessage()); - } - @ExceptionHandler - public ResultEntity InvalidParamHandle(InvalidParamException e) { - LOG.error(e.getMessage(), e); - return ResultEntity.faild(ResultCode.INVALID_PARAM_FAILD, e.getMessage()); - } - - @ExceptionHandler - public ResultEntity IllegalParamHandle(IllegalParamException e) { - LOG.error(e.getMessage(), e); - return ResultEntity.faild(ResultCode.REQUEST_FAILD, e.getMessage()); + return ResultEntity.failed(ResultCode.ILLEGAL_PARAM_FAILED, e.getMessage()); } @ExceptionHandler public ResultEntity serverErrorHandle(ServerErrorException e) { LOG.error(e.getMessage(), e); - return ResultEntity.faild(ResultCode.SERVER_ERROR, e.getMessage()); + return ResultEntity.failed(ResultCode.SERVER_ERROR, e.getMessage()); } @ExceptionHandler - public ResultEntity expiredSessionHandle(ExpiredSessionException e) { + public ResultEntity expiredSessionHandle(SessionInvalidException e) { LOG.error(e.getMessage(), e); - return ResultEntity.faild(ResultCode.EXPIRED_SESSION, e.getMessage()); + return ResultEntity.failed(ResultCode.EXPIRED_SESSION, e.getMessage()); } @ExceptionHandler public ResultEntity unauthorizedHandle(UnauthorizedException e) { LOG.error(e.getMessage(), e); - return ResultEntity.faild(ResultCode.UNAUTHORIZED, e.getMessage()); + return ResultEntity.failed(ResultCode.UNAUTHORIZED, e.getMessage()); } @ExceptionHandler public ResultEntity unknownHandle(Exception e) { LOG.error(e.getMessage(), e); - return ResultEntity.faild(ResultCode.UNKNOWN_FAILED, e.getMessage()); + return ResultEntity.failed(ResultCode.UNKNOWN_FAILED, e.getMessage()); } } diff --git a/common/src/main/java/name/guolanren/exception/IllegalParamException.java b/common/src/main/java/name/guolanren/exception/IllegalParamException.java index d1546a2..b234c68 100644 --- a/common/src/main/java/name/guolanren/exception/IllegalParamException.java +++ b/common/src/main/java/name/guolanren/exception/IllegalParamException.java @@ -5,8 +5,6 @@ */ public class IllegalParamException extends RuntimeException { - private static final long serialVersionUID = 975102355123055799L; - public IllegalParamException() { super(); } diff --git a/common/src/main/java/name/guolanren/exception/InvalidParamException.java b/common/src/main/java/name/guolanren/exception/InvalidParamException.java deleted file mode 100644 index 3e1020c..0000000 --- a/common/src/main/java/name/guolanren/exception/InvalidParamException.java +++ /dev/null @@ -1,31 +0,0 @@ -package name.guolanren.exception; - -/** - * @author guolanren - */ -public class InvalidParamException extends RuntimeException{ - - private static final long serialVersionUID = 975102355123055799L; - - public InvalidParamException() { - super(); - } - - public InvalidParamException(String message, Throwable cause, - boolean enableSuppression, - boolean writableStackTrace) { - super(message, cause, enableSuppression, writableStackTrace); - } - - public InvalidParamException(String message, Throwable cause) { - super(message, cause); - } - - public InvalidParamException(String message) { - super(message); - } - - public InvalidParamException(Throwable cause) { - super(cause); - } -} diff --git a/common/src/main/java/name/guolanren/exception/SessionInvalidException.java b/common/src/main/java/name/guolanren/exception/SessionInvalidException.java new file mode 100644 index 0000000..c367a3f --- /dev/null +++ b/common/src/main/java/name/guolanren/exception/SessionInvalidException.java @@ -0,0 +1,29 @@ +package name.guolanren.exception; + +/** + * @author guolanren + */ +public class SessionInvalidException extends RuntimeException { + + public SessionInvalidException() { + super(); + } + + public SessionInvalidException(String message, Throwable cause, + boolean enableSuppression, + boolean writableStackTrace) { + super(message, cause, enableSuppression, writableStackTrace); + } + + public SessionInvalidException(String message, Throwable cause) { + super(message, cause); + } + + public SessionInvalidException(String message) { + super(message); + } + + public SessionInvalidException(Throwable cause) { + super(cause); + } +} diff --git a/common/src/main/java/name/guolanren/http/ResultEntity.java b/common/src/main/java/name/guolanren/http/ResultEntity.java deleted file mode 100644 index 651e4c0..0000000 --- a/common/src/main/java/name/guolanren/http/ResultEntity.java +++ /dev/null @@ -1,58 +0,0 @@ -package name.guolanren.http; - -/** - * @author guolanren - */ -public class ResultEntity { - - private Integer code; - private String msg; - private T data; - - public static ResultEntity success() { - ResultEntity result = new ResultEntity(); - result.setCode(ResultCode.REQUEST_SUCCESS.getCode()); - result.setMsg(ResultCode.REQUEST_SUCCESS.getDescription()); - return result; - } - - public static ResultEntity success(T data) { - ResultEntity result = new ResultEntity(); - result.setCode(ResultCode.REQUEST_SUCCESS.getCode()); - result.setMsg(ResultCode.REQUEST_SUCCESS.getDescription()); - result.setData(data); - return result; - } - - public static ResultEntity faild(ResultCode code, T data) { - ResultEntity result = new ResultEntity(); - result.setCode(code.getCode()); - result.setMsg(code.getDescription()); - result.setData(data); - return result; - } - - public Integer getCode() { - return code; - } - - public void setCode(Integer 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; - } -} diff --git a/common/src/main/java/name/guolanren/http/ResultCode.java b/common/src/main/java/name/guolanren/http/response/ResultCode.java similarity index 56% rename from common/src/main/java/name/guolanren/http/ResultCode.java rename to common/src/main/java/name/guolanren/http/response/ResultCode.java index bcc00c8..961706f 100644 --- a/common/src/main/java/name/guolanren/http/ResultCode.java +++ b/common/src/main/java/name/guolanren/http/response/ResultCode.java @@ -1,4 +1,4 @@ -package name.guolanren.http; +package name.guolanren.http.response; /** * @author guolanren @@ -6,44 +6,49 @@ public enum ResultCode { /** - * 响应成功 + * 请求成功 */ - REQUEST_SUCCESS(100, "响应成功"), + REQUEST_SUCCESS(1000, "请求成功"), /** - * 请求失败 + * 非法参数 */ - REQUEST_FAILED(200, "请求失败"), + ILLEGAL_PARAM_FAILED(2001, "非法参数"), /** - * 无效请求参数 + * 服务端错误 */ - INVALID_PARAM_FAILED(201, "无效参数"), + SERVER_ERROR(3000, "服务器错误"), /** - * 非法请求参数 + * 无效会话 */ - ILLEGAL_PARAM_FAILED(202, "非法参数"), + EXPIRED_SESSION(4001, "无效失效"), /** - * 服务器错误 + * 未授权 */ - SERVER_ERROR(301, "服务器错误"), + UNAUTHORIZED(4002, "未授权"), /** - * Session失效 + * 重定向 */ - EXPIRED_SESSION(401, "SESSION失效"), + REDIRECT(5001, "重定向"), /** - * 未授权 + * 转发 + */ + FORWARD(5002, "转发"), + + /** + * 业务错误 */ - UNAUTHORIZED(402, "未授权"), + BUSINESS_FAIL(10000, "业务异常"), /** * 未知异常 */ - UNKNOWN_FAILED(900, "未知异常"); + UNKNOWN_FAILED(-1, "未知异常"); private Integer code; private String description; diff --git a/common/src/main/java/name/guolanren/http/response/ResultEntity.java b/common/src/main/java/name/guolanren/http/response/ResultEntity.java new file mode 100644 index 0000000..a656ead --- /dev/null +++ b/common/src/main/java/name/guolanren/http/response/ResultEntity.java @@ -0,0 +1,74 @@ +package name.guolanren.http.response; + +/** + * @author guolanren + */ +public class ResultEntity { + + private Integer errCode; + private String errMsg; + private T data; + + public static ResultEntity success() { + ResultEntity result = new ResultEntity(); + result.setErrCode(ResultCode.REQUEST_SUCCESS.getCode()); + result.setErrMsg(ResultCode.REQUEST_SUCCESS.getDescription()); + return result; + } + + public static ResultEntity success(T data) { + ResultEntity result = new ResultEntity(); + result.setErrCode(ResultCode.REQUEST_SUCCESS.getCode()); + result.setErrMsg(ResultCode.REQUEST_SUCCESS.getDescription()); + result.setData(data); + return result; + } + + public static ResultEntity failed(ResultCode code, T data) { + ResultEntity result = new ResultEntity(); + result.setErrCode(code.getCode()); + result.setErrMsg(code.getDescription()); + result.setData(data); + return result; + } + + public static ResultEntity redirect(String url) { + ResultEntity result = new ResultEntity(); + result.setErrCode(ResultCode.REDIRECT.getCode()); + result.setErrMsg(ResultCode.REDIRECT.getDescription()); + result.setData(url); + return result; + } + + public static ResultEntity forward(String path) { + ResultEntity result = new ResultEntity(); + result.setErrCode(ResultCode.FORWARD.getCode()); + result.setErrMsg(ResultCode.FORWARD.getDescription()); + result.setData(path); + return result; + } + + public Integer getErrCode() { + return errCode; + } + + public void setErrCode(Integer errCode) { + this.errCode = errCode; + } + + public String getErrMsg() { + return errMsg; + } + + public void setErrMsg(String errMsg) { + this.errMsg = errMsg; + } + + public T getData() { + return data; + } + + public void setData(T data) { + this.data = data; + } +}