//加上该注解,交给IOC管理
@Component
public class CustomExceptionResolver implements HandlerExceptionResolver {
@Override
public ModelAndView resolveException(HttpServletRequest request, HttpServletResponse response, Object handler,
Exception ex) {
//统一处理异常
CustomException customException = null;
if(ex instanceof CustomException){
customException = (CustomException) ex;
} else {
customException = new CustomException("系统错误,请与系统管理 员联系!");
}
//设置数据
ModelAndView modelAndView = new ModelAndView();
modelAndView.addObject("message", customException.getMessage());
modelAndView.setViewName("error");
return modelAndView;
}
}