what different between InternalResourceViewResolver vs UrlBasedViewResolver

前端 未结 3 1183
小蘑菇
小蘑菇 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: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

提交回复
热议问题