第一步:定义全局异常处理类
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.BindException;
import org.springframework.validation.FieldError;
import org.springframework.web.bind.MethodArgumentNotValidException;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;
import java.util.Objects;
/**
* 统一异常处理器
*/
@ControllerAdvice
@Slf4j
public class GlobalExceptionHandler {
/**
* 请求参数验证异常处理
* @param ex
* @return
*/
@ExceptionHandler({BindException.class, MethodArgumentNotValidException.class})
@ResponseBody
public BaseBean handlerMethodArgumentNotVaildException(Exception ex){
FieldError fieldError ;
if (ex instanceof MethodArgumentNotValidException){
MethodArgumentNotValidException vex = (MethodArgumentN