Spring View Resolver
By AmarSivas | | Updated : 2021-03-15 | Viewed : 10254 times
Spring MVC ViewResolver introduction
Spring MVC provided interfaces called ViewResolver and View, which are useful for deciding the view in which data model will be populated. Here ViewResolver contains the mapping between view name and view. So it will exact view with location then the model will be prepared as view and will be rendered in the browser.Please find the below given diagram for control flow.
After creation model object, the control’s responsibility is to display the data in the browser. But raw model cannot be used to display in the browser. So View or JSP will have to prepare html template by executing the logic. So controller need to send model to the View/JSP page. But controller does not know the view name and its location. Here View resolver will resolve name and location of that JSP. In the JSP page, the model will prepared as the html template. The prepared html template which contains the model will be populated in the browser through controller.
Spring provides different type of resolvers for deciding the view. After resolution, the model will be prepared as view and rendered in the browser.
Different type of ViewResolvers
AbstractCachingViewResolver: is an interface which will be used for caching certain views.
XmlViewResolver: will allows to define views in XML file. Spring will use XML configuration file to decide the view.
ResourceBundleViewResolver: will be used to configure views in resource bundle (properties file). Spring will use this file to resolve the views in which model will be rendered.
UrlBasedViewResolver: will allows direct resolution of view names to URL without explicit mapping.A defined symbolic name in controller class will be decided the view name with location.
InternalResourceViewResolver: this is convenient class for UrlBasedViewResolver for view configuration.
FreeMarkerViewResolver: is convenient subclass of UrlBasedViewResolver that supports FreeMarkerView
ContentNegotiatingViewResolver: resolves a view based on the request file name or Accept header.