开发者

What's the default Spring 3 view resolver?

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开发者_如何学Go?

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?


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜