Quellcode durchsuchen

全局异常捕获

lfj vor 3 Jahren
Ursprung
Commit
ccff4f1134

+ 24 - 0
fjs-scenic-manager/src/main/java/com/fjs/scenic/config/MyExceptionHandler.java

@@ -0,0 +1,24 @@
+package com.fjs.scenic.config;
+
+import com.fjs.scenic.utils.ReturnResult;
+import lombok.Data;
+import org.springframework.web.bind.annotation.ControllerAdvice;
+import org.springframework.web.bind.annotation.ExceptionHandler;
+import org.springframework.web.bind.annotation.ResponseBody;
+
+/**
+ * @program: fjs-parent
+ * @description: 全局异常捕获
+ * @author: lfj
+ * @since: 2021-09-30 16:15
+ **/
+
+@ControllerAdvice
+public class MyExceptionHandler {
+
+    @ExceptionHandler(value =Exception.class)
+    @ResponseBody
+    public ReturnResult exceptionHandler(Exception e){
+        return ReturnResult.error(e.getMessage());
+    }
+}