what different between InternalResourceViewResolver vs UrlBasedViewResolver

前端 未结 3 1150
小蘑菇
小蘑菇 2021-01-31 18:32

I just started using Spring. I came across a lot tutorials. I saw more examples using InternalResourceViewResolver than UrlBasedViewResolver. I looked

相关标签:
3条回答
  • 2021-01-31 18:39

    Spring supports a wide range of view technologies. ViewResolvers are here to plug any of the known supported view technologies into your application.

    UrlBasedViewResolver is a simple view resolver which simply resolves views of different technologies, by matching URL patterns to corresponding file names.

    UrlBasedViewResolver is here to support all the view technologies of type "AbstractUrlBasedView".

    AbstractJasperReportsView, AbstractPdfStamperView, AbstractTemplateView, InternalResourceView, RedirectView, TilesView, XsltView are the known subclasses of 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).

    InternalResourceViewResolver is a subclass of 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.

    I think this answers your question.

    0 讨论(0)
  • 2021-01-31 18:50

    InternalResourceViewResolver is infact subclass of 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.

    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.

    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)

    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.

    Some other URLBasedViewReolver s are

    1. InternalResourceViewResolver
    2. VelocityViewReolver
    3. FreeMarkerViewReolver
    4. ThymeleafViewResolver
    5. XsltViewReolver
    0 讨论(0)
  • 2021-01-31 19:06

    InternalResourceViewResolver is a convenient subclass of UrlBasedViewResolver.

    The JavaDoc describes some added properties in InternalResourceViewResolver that might be useful in some situations:

    Convenient subclass of UrlBasedViewResolver that supports InternalResourceView (i.e. Servlets and JSPs) and subclasses such as JstlView.

    AlwaysInclude: Controls whether either a forward or include is done.

    ExposeContextBeansAsAttributes: Allows all beans in context to be available as request attributes, which means they can be referenced from the EL in JSP.

    ExposedContextBeanNames: If non-null, specifies the list of beans that will be exposed, as opposed to all of them.

    Source from spring forum : Spring Q&A forum

    0 讨论(0)
提交回复
热议问题