What's the default Spring 3 view resolver?

前提是你 提交于 2021-02-18 22:24:47

问题


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?


回答1:


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.



来源:https://stackoverflow.com/questions/6607598/whats-the-default-spring-3-view-resolver

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!