From a99c1f36e52c75e0020127c62d39c1eddae4a036 Mon Sep 17 00:00:00 2001
From: chenlu <1320612696@qq.com>
Date: 星期一, 28 七月 2025 17:07:54 +0800
Subject: [PATCH] Merge branch 'master' of http://bore.pub:10439/r/ERP_override
---
north-glass-erp/src/main/java/com/example/erp/config/ExceptionController.java | 30 ++++++++++++++++++++++++++++++
1 files changed, 30 insertions(+), 0 deletions(-)
diff --git a/north-glass-erp/src/main/java/com/example/erp/config/ExceptionController.java b/north-glass-erp/src/main/java/com/example/erp/config/ExceptionController.java
new file mode 100644
index 0000000..fd773f7
--- /dev/null
+++ b/north-glass-erp/src/main/java/com/example/erp/config/ExceptionController.java
@@ -0,0 +1,30 @@
+package com.example.erp.config;
+
+import com.example.erp.common.Result;
+import org.mybatis.logging.Logger;
+import org.mybatis.logging.LoggerFactory;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.http.HttpStatus;
+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 org.springframework.web.bind.annotation.ResponseStatus;
+
+@ControllerAdvice
+public class ExceptionController {
+ private final Logger log = LoggerFactory.getLogger(ExceptionController.class);
+
+
+ @ResponseStatus(value = HttpStatus.BAD_REQUEST)
+ @ExceptionHandler(MethodArgumentNotValidException.class)
+ @ResponseBody
+ public Result getMessage(MethodArgumentNotValidException exception){
+ Result result = new Result();
+ result.setCode("400");
+ String message = exception.getBindingResult().getFieldError().getDefaultMessage();
+ // exception.getBindingResult().getFieldErrors(); 鑾峰彇鎵�鏈夌殑閿欒淇℃伅
+ result.setMsg("'"+exception.getBindingResult().getFieldError().getField()+"':"+message);
+ return result;
+ }
+}
--
Gitblit v1.8.0