From 2ae0b3c4b3dd7597beedc90c2e7fb9e12f1e737b Mon Sep 17 00:00:00 2001 From: Jerry Yan <792602257@qq.com> Date: Thu, 5 Jun 2025 14:24:47 +0800 Subject: [PATCH] =?UTF-8?q?=E5=8F=82=E6=95=B0=E9=94=99=E8=AF=AF=E6=89=93?= =?UTF-8?q?=E5=8D=B0=E9=94=99=E8=AF=AF=E8=AF=B7=E6=B1=82=E5=9C=B0=E5=9D=80?= =?UTF-8?q?=E6=96=B9=E4=BE=BF=E6=8E=92=E6=9F=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/ycwl/basic/exception/CustomExceptionHandle.java | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/main/java/com/ycwl/basic/exception/CustomExceptionHandle.java b/src/main/java/com/ycwl/basic/exception/CustomExceptionHandle.java index 581a35b..568e056 100644 --- a/src/main/java/com/ycwl/basic/exception/CustomExceptionHandle.java +++ b/src/main/java/com/ycwl/basic/exception/CustomExceptionHandle.java @@ -2,6 +2,7 @@ package com.ycwl.basic.exception; import com.ycwl.basic.enums.BizCodeEnum; import com.ycwl.basic.utils.ApiResponse; +import jakarta.servlet.http.HttpServletRequest; import org.apache.tomcat.util.http.fileupload.impl.SizeLimitExceededException; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -11,6 +12,8 @@ import org.springframework.web.bind.annotation.ExceptionHandler; import org.springframework.web.bind.annotation.RestControllerAdvice; import jakarta.servlet.http.HttpServletResponse; +import org.springframework.web.method.annotation.MethodArgumentTypeMismatchException; + import java.io.IOException; /** @@ -54,6 +57,12 @@ public class CustomExceptionHandle { response.setStatus(HttpStatus.INTERNAL_SERVER_ERROR.value()); return ApiResponse.buildResponse(bizException.getCode(), bizException.getMsg()); } + @ExceptionHandler(value = MethodArgumentTypeMismatchException.class) + public ApiResponse handle(HttpServletRequest request, HttpServletResponse response, MethodArgumentTypeMismatchException exception) { + response.setStatus(HttpStatus.INTERNAL_SERVER_ERROR.value()); + LOGGER.error("参数错误 -> 请求地址:{},请求方式:{}", request.getRequestURI(), request.getMethod()); + return ApiResponse.buildResponse(5000, "参数错误!"); + } @ExceptionHandler(value =IOException.class) public ApiResponse handle(HttpServletResponse response, IOException e) {