From ec46a32ca330e5c416302eb082e44fa164b37829 Mon Sep 17 00:00:00 2001
From: xieb <vip_xiaobin810@163.com>
Date: Fri, 22 Sep 2023 17:41:16 +0800
Subject: [PATCH] 配置修改
---
src/main/java/com/dji/sample/component/GlobalExceptionHandler.java | 8 +++++---
1 files changed, 5 insertions(+), 3 deletions(-)
diff --git a/src/main/java/com/dji/sample/component/GlobalExceptionHandler.java b/src/main/java/com/dji/sample/component/GlobalExceptionHandler.java
index b0a9fbf..0b6b6b0 100644
--- a/src/main/java/com/dji/sample/component/GlobalExceptionHandler.java
+++ b/src/main/java/com/dji/sample/component/GlobalExceptionHandler.java
@@ -1,6 +1,7 @@
package com.dji.sample.component;
import com.dji.sample.common.model.ResponseResult;
+import org.springframework.validation.BindException;
import org.springframework.web.bind.MethodArgumentNotValidException;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
@@ -32,9 +33,10 @@
return ResponseResult.error("A null object appeared.");
}
- @ExceptionHandler(MethodArgumentNotValidException.class)
- public ResponseResult methodArgumentNotValidExceptionHandler(MethodArgumentNotValidException e) {
- return ResponseResult.error(e.getBindingResult().getAllErrors().get(0).getDefaultMessage());
+ @ExceptionHandler({MethodArgumentNotValidException.class, BindException.class})
+ public ResponseResult methodArgumentNotValidExceptionHandler(BindException e) {
+ e.printStackTrace();
+ return ResponseResult.error(e.getFieldError().getField() + e.getFieldError().getDefaultMessage());
}
}
--
Gitblit v1.9.3