package com.zjqy.qbcs.security.error;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.servlet.ModelAndView;
/**
* 全局异常跳转页面
*/
@ControllerAdvice
public class IMoocExceptionHandler {
public static final String IMOOC_ERROR_VIEW = "error";
@ExceptionHandler(value = Exception.class)
public Object errorHandler(HttpServletRequest reqest,
HttpServletResponse response, Exception e) throws Exception {
e.printStackTrace();
ModelAndView mav = new ModelAndView();
mav.addObject("exception", e);
mav.addObject("url", reqest.getRequestURL());
mav.setViewName(IMOOC_ERROR_VIEW);
return mav;
}
}
<!DOCTYPE html>
<html lang="zh-CN" xmlns:th="http://www.thymeleaf.org" xmlns:sec="http://www.thymeleaf.org/thymeleaf-extras-springsecurity3">
<head>
<meta charset="UTF-8">
<title>首页</title>
</head>
<body>
<h1 style="color: red">发生错误:</h1>
<div th:text="${url}"></div>
<div th:text="${exception.message}"></div>
就算是系统报错我也要说只是网络有问题! 404
"\t\t * _ooOoo_\n" +
"\t\t * o8888888o\n" +
"\t\t * 88\" . \"88\n" +
"\t\t * (| -_- |)\n" +
"\t\t * O\\ = /O\n" +
"\t\t * ____/`---'\\____\n" +
"\t\t * .' \\\\| |// `.\n" +
"\t\t * / \\\\||| : |||// \\\n" +
"\t\t * / _||||| -:- |||||- \\\n" +
"\t\t * | | \\\\\\ - /// | |\n" +
"\t\t * | \\_| ''\\---/'' | |\n" +
"\t\t * \\ .-\\__ `-` ___/-. /\n" +
"\t\t * ___`. .' /--.--\\ `. . __\n" +
"\t\t * .\"\" '< `.___\\_<|>_/___.' >'\"\".\n" +
"\t\t * | | : `- \\`.;`\\ _ /`;.`/ - ` : | |\n" +
"\t\t * \\ \\ `-. \\_ __\\ /__ _/ .-` / /\n" +
"\t\t * ======`-.____`-.___\\_____/___.-`____.-'======\n" +
"\t\t * `=---='\n" +
"\t\t * ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" +
"\t\t * 佛祖保佑 永无BUG\n" +
"\t\t * 佛曰:\n" +
"\t\t * 写字楼里写字间,写字间里程序员;\n" +
"\t\t * 程序人员写程序,又拿程序换酒钱。\n" +
"\t\t * 酒醒只在网上坐,酒醉还来网下眠;\n" +
"\t\t * 酒醉酒醒日复日,网上网下年复年。\n" +
"\t\t * 但愿老死电脑间,不愿鞠躬老板前;\n" +
"\t\t * 奔驰宝马贵者趣,公交自行程序员。\n" +
"\t\t * 别人笑我忒疯癫,我笑自己命太贱;\n" +
"\t\t * 不见满街漂亮妹,哪个归得程序员?"
</body>
</html>
写一个html,让报错,都来这里