From 40934da83d6c4e2ecbabb521b8bb54a903070e7c Mon Sep 17 00:00:00 2001
From: guoshilong <123456>
Date: Sat, 23 Sep 2023 16:48:12 +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