SpringMVC自定义错误页面

来源:互联网 发布:php查找字符串位置 编辑:程序博客网 时间:2024/06/06 03:34
0、springboot 项目中,使用过
@Controllerclass ErrorController extends BasicErrorController  的方式进行处理
1、在SpringMVC中,实现
class MyExceptionHandler implements HandlerExceptionResolver  ,然后在配置文件里面@Bean 即可。
重载方法
ModelAndView resolveException(HttpServletRequest httpServletRequest, 
HttpServletResponse httpServletResponse, Object o, Exception e) 
e 可以得到错误信息, 可根据request 情况判断是页面出错还是ajax等出错。
返回不同的ModelAndView ,或者直接在response里回写,函数返回Null.