java InternalResourceViewResolver 和 UrlBasedViewResolver 有什么不同
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/17453032/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
what different between InternalResourceViewResolver vs UrlBasedViewResolver
提问by DarkVision
I just started using Spring. I came across a lot tutorials.
I saw more examples using InternalResourceViewResolver
than UrlBasedViewResolver
. I looked at the Spring documentation, but I can't figure out the benefit of using one or the other. Can someone provide some explanation?
我刚开始使用Spring。我遇到了很多教程。我看到使用InternalResourceViewResolver
比UrlBasedViewResolver
. 我查看了 Spring 文档,但无法弄清楚使用其中一个的好处。有人可以提供一些解释吗?
采纳答案by NINCOMPOOP
InternalResourceViewResolver
is a convenient subclass of UrlBasedViewResolver
.
InternalResourceViewResolver
是 的一个方便的子类UrlBasedViewResolver
。
The JavaDoc describes some added properties in InternalResourceViewResolver
that might be useful in some situations:
JavaDoc 描述了一些InternalResourceViewResolver
在某些情况下可能有用的附加属性:
Convenient subclass of UrlBasedViewResolver that supports InternalResourceView(i.e. Servlets and JSPs) and subclasses such as JstlView.
UrlBasedViewResolver 的便捷子类,支持InternalResourceView(即 Servlet 和 JSP)和 JstlView 等子类。
AlwaysInclude
: Controls whether either a forward or include is done.
AlwaysInclude
: 控制是完成转发还是包含。
ExposeContextBeansAsAttributes
: Allows all beans in context to be available as request attributes, which means they can be referenced from the EL in JSP.
ExposeContextBeansAsAttributes
: 允许上下文中的所有 bean 作为请求属性可用,这意味着它们可以从 JSP 中的 EL 中引用。
ExposedContextBeanNames
: If non-null, specifies the list of beans that will be exposed, as opposed to all of them.
ExposedContextBeanNames
: 如果非空,则指定将公开的 bean 列表,而不是所有这些 bean。
Source from spring forum : Spring Q&A forum
来源:Spring论坛:Spring Q&A 论坛
回答by Sazzadur Rahaman
Spring supports a wide range of view technologies. ViewResolvers are here to plug any of the known supported view technologies into your application.
Spring 支持广泛的视图技术。ViewResolvers 可以将任何已知的受支持的视图技术插入到您的应用程序中。
UrlBasedViewResolveris a simple view resolver which simply resolves views of different technologies, by matching URL
patterns to corresponding file names.
UrlBasedViewResolver是一个简单的视图解析器,它通过将URL
模式与相应的文件名匹配来简单地解析不同技术的视图。
UrlBasedViewResolver
is here to support all the view technologies of type "AbstractUrlBasedView".
UrlBasedViewResolver
在这里支持“ AbstractUrlBasedView”类型的所有视图技术。
AbstractJasperReportsView
, AbstractPdfStamperView
, AbstractTemplateView
, InternalResourceView
, RedirectView
, TilesView
, XsltView
are the known subclasses of AbstractUrlBasedView
.
AbstractJasperReportsView
, AbstractPdfStamperView
, AbstractTemplateView
, InternalResourceView
, RedirectView
, TilesView
,XsltView
是 的已知子类AbstractUrlBasedView
。
So when you are using UrlBasedViewResolver
you can use any one of the subclasses of AbstractUrlBasedView
as the type of your view technology (by setting the corresponding viewClass only).
所以当你使用的时候UrlBasedViewResolver
你可以使用任何一个子类AbstractUrlBasedView
作为你的视图技术的类型(通过只设置相应的viewClass)。
InternalResourceViewResolveris a subclass of UrlBasedViewResolver
.
InternalResourceViewResolver是UrlBasedViewResolver
.
But when you are using InternalResourceViewResolver
, (which is a convenient subclass of UrlBasedViewResolver
), you can only use the technology of type InternalResourceView
as your view technology.
但是当你使用InternalResourceViewResolver
, (它是 的一个方便的子类UrlBasedViewResolver
)时,你只能使用 type 技术InternalResourceView
作为你的视图技术。
I think this answers your question.
我想这回答了你的问题。
回答by Aniket Thakur
InternalResourceViewResolver
is infact subclass of UrlBasedViewResolver
.
InternalResourceViewResolver
实际上是 的子类UrlBasedViewResolver
。
UrlBasedViewResolver
- View name is directly resolved to an URL. No explicit mapping is provided. View name would be the URL itself or you can add a prefix
or suffix
as per your design. You can also prefix as "redirect:" and "forward:" to redirect and forward your request.
UrlBasedViewResolver
- 视图名称直接解析为 URL。没有提供显式映射。视图名称将是 URL 本身,或者您可以根据您的设计添加prefix
或suffix
。您还可以使用前缀“redirect:”和“forward:”来重定向和转发您的请求。
InternalResourceViewResolver
- Subclass of UrlBasedViewResolver that supports InternalResourceView. An InternalResourceView
wraps JSP or some other resource of the same web app. You can access models in the JSP using EL.
InternalResourceViewResolver
- 支持 InternalResourceView 的 UrlBasedViewResolver 的子类。一个InternalResourceView
包裹JSP或相同的web应用程序的一些其他资源。您可以使用 EL 访问 JSP 中的模型。
NOTE: Some URLBasedViewResolvers (Tiles, Velocity,Freemarker) check if resource exist and return null. So they can be anywhere in the view resolver chain. Others must be last (JSTL/JSP, XSLT, JSON)
注意:一些 URLBasedViewResolvers(Tiles、Velocity、Freemarker)检查资源是否存在并返回 null。因此它们可以位于视图解析器链中的任何位置。其他必须在最后(JSTL/JSP、XSLT、JSON)
So InternalResourceViewResolver
needs to be last in the chain of view resolvers since it resolves view name whether the actual resource is present or not.
所以InternalResourceViewResolver
需要在视图解析器链中的最后,因为无论实际资源是否存在,它都会解析视图名称。
Some other URLBasedViewReolver s are
其他一些 URLBasedViewReolver 是
- InternalResourceViewResolver
- VelocityViewReolver
- FreeMarkerViewReolver
- ThymeleafViewResolver
- XsltViewReolver
- 内部资源视图解析器
- VelocityViewReolver
- FreeMarkerViewReolver
- ThymeleafViewResolver
- XsltViewReolver