看看ControllerAdvice,您可以执行以下操作:
@ControllerAdvicepublic class ExceptionHandlerController { public static final String DEFAULT_ERROR_VIEW = "error"; @ExceptionHandler(value = {Exception.class, RuntimeException.class}) public ModelAndView defaultErrorHandler(HttpServletRequest request, Exception e) { ModelAndView mav = new ModelAndView(DEFAULT_ERROR_VIEW); mav.addObject("datetime", new Date()); mav.addObject("exception", e); mav.addObject("url", request.getRequestURL()); return mav; }}


