如何使用Spring MVCSpring Boot编写适当的全局错误处理程序

如何使用Spring MVCSpring Boot编写适当的全局错误处理程序,第1张

如何使用Spring MVC / Spring Boot编写适当的全局错误处理程序

看看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;    }}


欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/zaji/5000369.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-11-14
下一篇2022-11-14

发表评论

登录后才能评论

评论列表(0条)

    保存