zhangherong
2025-07-05 009097bce23998af709ae238e62ad8d975cc9891
lxzn-boot-base-core/src/main/java/org/jeecg/common/exception/JeecgBootExceptionHandler.java
@@ -10,6 +10,7 @@
import org.springframework.data.redis.connection.PoolException;
import org.springframework.http.HttpStatus;
import org.springframework.web.HttpRequestMethodNotSupportedException;
import org.springframework.web.bind.MethodArgumentNotValidException;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseStatus;
import org.springframework.web.bind.annotation.RestControllerAdvice;
@@ -17,6 +18,9 @@
import org.springframework.web.servlet.NoHandlerFoundException;
import lombok.extern.slf4j.Slf4j;
import java.util.HashMap;
import java.util.Map;
/**
 * 异常处理器
@@ -29,6 +33,21 @@
public class JeecgBootExceptionHandler {
   /**
    * @Valid 抛出异常处理
    * @param
    * @return
    */
   @ExceptionHandler(MethodArgumentNotValidException.class)
   public Result<?> handleMethodArgumentNotValidException(MethodArgumentNotValidException ex){
      Map<String, Object> errors = new HashMap<>();
      ex.getBindingResult().getFieldErrors().forEach(error -> {
         errors.put(error.getField(), error.getDefaultMessage());
      });
      log.error(ex.getMessage(), ex);
      return Result.error(errors.toString());
   }
   /**
    * 处理自定义异常
    */
   @ExceptionHandler(JeecgBootException.class)