I've read Spring 3 docs about view resolvers... But in my project I didn't define any. I just return a ModelAndView
or @ResponseBody
String from the controller methods. I guess there is a default view resolver (perhaps UrlBasedViewResolver
) that is already configured. What is that? Where can I get info in the docs about this?
If I want to add other views like JsonView
or XmlView
(right now I use a Jsp that renders the data, but I read I can avoid this by passing model Objects directly to special views that will do this for me) how do I deal with this default view resolver?
Thymeleaf view resolver works by surrounding the view name with a prefix and suffix. The default values of prefix and suffix are 'classpath:/templates/' and '. html', respectively. Spring Boot also provides an option to change the default value of prefix and suffix by setting spring.
2) The InternalResourceViewResolver is also the default view resolver of DispatcherServlet class, which acts as the front controller in the Spring MVC framework.
An implementation of ViewResolver that accepts a configuration file written in XML with the same DTD as Spring's XML bean factories. The default configuration file is /WEB-INF/views. xml .
Spring MVC is a Web MVC Framework for building web applications. In generic all MVC frameworks provide a way of working with views. Spring does that via the ViewResolvers, which enables you to render models in the browser without tying the implementation to specific view technology.
The default is an automatically-registered InternalResourceViewResolver
(UrlBasedViewResolver
is an abstract superclass of this).
If you declare your own view resolver(s), then the default InternalResourceViewResolver
will not be used. You can, if you, wish, simply redeclare it as an explicit bean. If there are multiple view resolvers, then they will be consulted in order until one of them returns a view object. However, because of the way that the servlet API works, InternalResourceViewResolver
must always be the last view resolver in the chain.
If your controller method returns a View
object directly, then no view resolver is necessary, and the view will be rendered directly. Similarly, if you use @ResponseBody
, the view resolver is bypassed.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With