springboot-ControllerAdvice全局捕获异常

//开启全局捕获异常
@ControllerAdvice
public class GlobalExceptionHandler {

    @ExceptionHandler(RuntimeException.class)//拦截所有运行时异常
    @ResponseBody //ResponseBody返回json。
    // 如果是跳转到错误页面就直接写页面地址,返回String跳转到页面。
    public Map<String ,Object> errorMap(){
        Map<String,Object> result=new HashMap<String ,Object>();
        result.put("errorCode","500");
        result.put("errorMsg","系统异常");
        return result;
    }

}

 

猜你喜欢

转载自blog.csdn.net/yfsread/article/details/81146699