全局异常捕获
package com.example.demo.controller;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;
@ControllerAdvice
public class ExceptionDemoController {
@ExceptionHandler({RuntimeException.class})
@ResponseBody
public String exceptionHandler(){
return "错误信息显示内容";
}
}
将系统中的异常进行统一捕获