diff --git a/whatsmars-common/src/main/java/org/hongxi/whatsmars/common/result/ResultHelper.java b/whatsmars-common/src/main/java/org/hongxi/whatsmars/common/result/ResultHelper.java index a426cf76..c2b7b85d 100644 --- a/whatsmars-common/src/main/java/org/hongxi/whatsmars/common/result/ResultHelper.java +++ b/whatsmars-common/src/main/java/org/hongxi/whatsmars/common/result/ResultHelper.java @@ -5,33 +5,33 @@ */ public class ResultHelper { - public static Result newSuccessResult(T data) { - Result result = newSuccessResult(); + public static Result newSuccessResult(T data) { + Result result = newSuccessResult(); result.setData(data); return result; } - public static Result newErrorResult(int code, String message) { - return new Result(code, message); + public static Result newErrorResult(int code, String message) { + return new Result<>(code, message); } - public static Result newErrorResult() { + public static Result newErrorResult() { return newResult(false); } - public static Result newSuccessResult() { + public static Result newSuccessResult() { return newResult(true); } - public static Result newResult(boolean success) { + public static Result newResult(boolean success) { return newResult(success, null); } - public static Result newResult(boolean success, String message) { + public static Result newResult(boolean success, String message) { if (success) { - return new Result(200, message == null ? "操作成功" : message); + return new Result<>(200, message == null ? "操作成功" : message); } else { - return new Result(500, message == null ? "系统繁忙,请稍后再试" : message); + return new Result<>(500, message == null ? "系统繁忙,请稍后再试" : message); } } diff --git a/whatsmars-spring-boot-samples/whatsmars-boot-sample-web/src/main/java/org/hongxi/whatsmars/boot/sample/web/exception/DefaultExceptionHandler.java b/whatsmars-spring-boot-samples/whatsmars-boot-sample-web/src/main/java/org/hongxi/whatsmars/boot/sample/web/exception/DefaultExceptionHandler.java index 36038e36..393f389d 100644 --- a/whatsmars-spring-boot-samples/whatsmars-boot-sample-web/src/main/java/org/hongxi/whatsmars/boot/sample/web/exception/DefaultExceptionHandler.java +++ b/whatsmars-spring-boot-samples/whatsmars-boot-sample-web/src/main/java/org/hongxi/whatsmars/boot/sample/web/exception/DefaultExceptionHandler.java @@ -22,7 +22,7 @@ public class DefaultExceptionHandler { @ResponseStatus(HttpStatus.OK) @ExceptionHandler(BusinessException.class) @ResponseBody - public Result handleLogicException(HttpServletRequest request, BusinessException e) { + public Result handleLogicException(HttpServletRequest request, BusinessException e) { log.error("business exception handled, request:{}", request.getRequestURI(), e); return ResultHelper.newErrorResult(e.getCode(), e.getMsg()); } @@ -30,7 +30,7 @@ public Result handleLogicException(HttpServletRequest request, BusinessException @ResponseStatus(HttpStatus.OK) @ExceptionHandler(Exception.class) @ResponseBody - public Result handleException(HttpServletRequest request, Exception e) throws Exception { + public Result handleException(HttpServletRequest request, Exception e) throws Exception { if (AnnotationUtils.findAnnotation(e.getClass(), ResponseStatus.class) != null) { throw e; }