|
@@ -19,8 +19,10 @@ import org.springframework.http.server.ServerHttpRequest;
|
|
import org.springframework.http.server.ServerHttpResponse;
|
|
import org.springframework.http.server.ServerHttpResponse;
|
|
import org.springframework.security.access.AccessDeniedException;
|
|
import org.springframework.security.access.AccessDeniedException;
|
|
import org.springframework.validation.BindingResult;
|
|
import org.springframework.validation.BindingResult;
|
|
|
|
+import org.springframework.validation.FieldError;
|
|
import org.springframework.web.HttpRequestMethodNotSupportedException;
|
|
import org.springframework.web.HttpRequestMethodNotSupportedException;
|
|
import org.springframework.web.bind.MethodArgumentNotValidException;
|
|
import org.springframework.web.bind.MethodArgumentNotValidException;
|
|
|
|
+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.servlet.NoHandlerFoundException;
|
|
import org.springframework.web.servlet.NoHandlerFoundException;
|
|
@@ -28,6 +30,7 @@ import org.springframework.web.servlet.mvc.method.annotation.ResponseBodyAdvice;
|
|
|
|
|
|
import javax.security.auth.login.LoginException;
|
|
import javax.security.auth.login.LoginException;
|
|
import java.util.*;
|
|
import java.util.*;
|
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
|
|
/**
|
|
/**
|
|
* https://juejin.cn/post/6844903902811275278
|
|
* https://juejin.cn/post/6844903902811275278
|
|
@@ -108,6 +111,17 @@ public class GlobalExceptionHandler implements ResponseBodyAdvice<Object> {
|
|
);
|
|
);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ @ExceptionHandler(MissingServletRequestParameterException.class)
|
|
|
|
+ public Result handleMissingServletRequestParameterException(MissingServletRequestParameterException e) {
|
|
|
|
+ System.out.println("****** MissingServletRequestParameterException.class: ******");
|
|
|
|
+ System.out.println(e.getMessage());
|
|
|
|
+ return Result.error(
|
|
|
|
+ ResultEnum.PARAMETER_EXCEPTION.getCode(),
|
|
|
|
+ "缺少参数 " + e.getParameterName() + " 或类型不匹配 (" + e.getParameterType() + ")",
|
|
|
|
+ e.getMessage()
|
|
|
|
+ );
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
|
|
|
|
|
|
/**
|
|
/**
|