在Controller的方法中进行try…catch处
全局异常处理器
package com.web.management.exception;
import com.web.management.pojo.Result;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;
@RestControllerAdvice
public class GlobalExceptionHandler {
@ExceptionHandler(Exception.class)//进行全局异常抛出
public Result exception(Exception e) {
e.printStackTrace();
return Result.error("操作失败");
}
}