如何连接 ModelAndViewDefiningException 以将错误发送到我的视图
以最简单、最直接的方式,如何连接 ModelAndViewDefiningException 装饰物以将错误发送到我指定的视图?
这个人应该从: org.springframework.web.servlet.ModelAndViewDefiningException
提前非常感谢任何人!
In the easiest, most straightforward way, how do I wire up a/the ModelAndViewDefiningException doodad to send errors to my specified view?
This guy should be called from: org.springframework.web.servlet.ModelAndViewDefiningException
Much thanks to anyone in advance!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这是一个例外。你扔它!
ModelAndViewDefiningException
是ModelAndView
的异常包装器。 Spring 框架识别它、捕获它、从中提取模型和视图名称,然后转发到已解析的视图,将模型公开给视图。您可以在处理程序处理期间随时抛出它。通常,在 Controller 内 的代码通常不会引发异常,因为控制器请求处理程序方法返回
ModelAndView
。因此,您可以只返回ModelAndView
,而不是在ModelAndView
内部抛出异常。但有些情况下您无法返回
ModelAndView
。 拦截器是很好的例子,因为它们的方法返回的是void
或boolean
。如果拦截器内未满足某些条件,ModelAndViewDefiningException
允许您中断流程并转到错误视图。It's an exception. You throw it!
The
ModelAndViewDefiningException
is an exception wrapper for aModelAndView
. The Spring framework recognizes it, catches it, extracts the model and view name from it and forwards to the resolved view exposing the model to the view.You can throw it at any time during handler processing. Normally, inside a Controller's code you don't usually throw the exception because Controller request handler methods return a
ModelAndView
. So instead of throwing an exception with theModelAndView
inside, you can just return theModelAndView
.But there are situations when you can't return a
ModelAndView
. Interceptors are a good example of this because their methods are ofvoid
orboolean
return. If some condition isn't met inside the interceptor theModelAndViewDefiningException
allows you to break the flow and go to the error view.