From c73d6a1b27345fc95262472f39c12a37707c92de Mon Sep 17 00:00:00 2001 From: lin <648540858@qq.com> Date: Thu, 25 Jun 2026 16:26:22 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A4=84=E7=90=86=E5=85=A8=E5=B1=80=E5=BC=82?= =?UTF-8?q?=E5=B8=B8=20NoResourceFoundException?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../iot/vmp/conf/GlobalExceptionHandler.java | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/main/java/com/genersoft/iot/vmp/conf/GlobalExceptionHandler.java b/src/main/java/com/genersoft/iot/vmp/conf/GlobalExceptionHandler.java index 5e29ff42f..da0844d2b 100644 --- a/src/main/java/com/genersoft/iot/vmp/conf/GlobalExceptionHandler.java +++ b/src/main/java/com/genersoft/iot/vmp/conf/GlobalExceptionHandler.java @@ -11,6 +11,7 @@ import org.springframework.web.HttpRequestMethodNotSupportedException; import org.springframework.web.bind.annotation.ExceptionHandler; import org.springframework.web.bind.annotation.ResponseStatus; import org.springframework.web.bind.annotation.RestControllerAdvice; +import org.springframework.web.servlet.resource.NoResourceFoundException; /** * 全局异常处理 @@ -31,6 +32,17 @@ public class GlobalExceptionHandler { return WVPResult.fail(ErrorCode.ERROR500.getCode(), e.getMessage()); } + /** + * 默认异常处理 + * @param e 异常 + * @return 统一返回结果 + */ + @ExceptionHandler(NoResourceFoundException.class) + @ResponseStatus(HttpStatus.BAD_REQUEST) + public WVPResult exceptionHandler(NoResourceFoundException e) { + return WVPResult.fail(ErrorCode.ERROR404); + } + /** * 默认异常处理 * @param e 异常