mirror of
https://github.com/YunaiV/ruoyi-vue-pro.git
synced 2025-10-27 20:06:25 +08:00
feat:【framework 框架】增加对 MaxUploadSizeExceededException 文件上传过大的提示优化
This commit is contained in:
@ -36,6 +36,7 @@ import org.springframework.web.bind.MissingServletRequestParameterException;
|
|||||||
import org.springframework.web.bind.annotation.ExceptionHandler;
|
import org.springframework.web.bind.annotation.ExceptionHandler;
|
||||||
import org.springframework.web.bind.annotation.RestControllerAdvice;
|
import org.springframework.web.bind.annotation.RestControllerAdvice;
|
||||||
import org.springframework.web.method.annotation.MethodArgumentTypeMismatchException;
|
import org.springframework.web.method.annotation.MethodArgumentTypeMismatchException;
|
||||||
|
import org.springframework.web.multipart.MaxUploadSizeExceededException;
|
||||||
import org.springframework.web.servlet.NoHandlerFoundException;
|
import org.springframework.web.servlet.NoHandlerFoundException;
|
||||||
import org.springframework.web.servlet.resource.NoResourceFoundException;
|
import org.springframework.web.servlet.resource.NoResourceFoundException;
|
||||||
|
|
||||||
@ -93,6 +94,9 @@ public class GlobalExceptionHandler {
|
|||||||
if (ex instanceof ValidationException) {
|
if (ex instanceof ValidationException) {
|
||||||
return validationException((ValidationException) ex);
|
return validationException((ValidationException) ex);
|
||||||
}
|
}
|
||||||
|
if (ex instanceof MaxUploadSizeExceededException) {
|
||||||
|
return maxUploadSizeExceededExceptionHandler((MaxUploadSizeExceededException) ex);
|
||||||
|
}
|
||||||
if (ex instanceof NoHandlerFoundException) {
|
if (ex instanceof NoHandlerFoundException) {
|
||||||
return noHandlerFoundExceptionHandler((NoHandlerFoundException) ex);
|
return noHandlerFoundExceptionHandler((NoHandlerFoundException) ex);
|
||||||
}
|
}
|
||||||
@ -213,6 +217,14 @@ public class GlobalExceptionHandler {
|
|||||||
return CommonResult.error(BAD_REQUEST);
|
return CommonResult.error(BAD_REQUEST);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 处理上传文件过大异常
|
||||||
|
*/
|
||||||
|
@ExceptionHandler(MaxUploadSizeExceededException.class)
|
||||||
|
public CommonResult<?> maxUploadSizeExceededExceptionHandler(MaxUploadSizeExceededException ex) {
|
||||||
|
return CommonResult.error(BAD_REQUEST.getCode(), "上传文件过大,请调整后重试");
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 处理 SpringMVC 请求地址不存在
|
* 处理 SpringMVC 请求地址不存在
|
||||||
*
|
*
|
||||||
|
|||||||
Reference in New Issue
Block a user