SpringBoot —— 全局异常处理器

发布时间 2023-05-22 08:21:39作者: Rover20230226
 1 package com.itheima.handler;
 2 
 3 import com.itheima.vo.Result;
 4 import org.springframework.web.bind.annotation.ExceptionHandler;
 5 import org.springframework.web.bind.annotation.RestController;
 6 
 7 // 全局异常处理器
 8 @RestController
 9 public class GlobalExceptionHandler {
10 
11     @ExceptionHandler(Exception.class)
12     public Result ex(Exception ex) {
13         ex.printStackTrace();
14         return Result.error("对不起,操作失败,请联系管理员");
15     }
16 }