Spring MVC中的多视图解析器 [英] Multiple View resolvers in spring mvc

查看:289
本文介绍了Spring MVC中的多视图解析器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在基于Spring MVC的Web应用程序中使用多个视图解析器

I want to use multiple view resolvers in my web app based on spring mvc

任何人都可以告诉我如何实现这一目标.

Can anyone tell me how do I achieve that.

我想在我的应用程序中同时使用JSP和freemarker. 请提出一些方法或链接或示例.

I want to use both JSP and freemarker in my app. Please suggest some approaches or links or examples..

感谢所有帮助.

Adhir

推荐答案

您可以根据需要添加任意数量的视图解析器.您可以指定检查视图解析器的顺序. Spring将使用第一个可以成功解析视图的视图解析器.

You can add as many view resolvers as you want. You can specify the order in which the view resolvers need to be checked. Spring will take the first view resolver which can successfully resolve the view.

例如: 由于您具有JSP和freemarker,因此请为两者添加视图解析器,并为JSP赋予order属性,为freemarker赋予order属性2. 如果您的视图是/freemarker/hello.ftl,则JSP resoplver将失败,因为它将无法找到文件/freemarker/hello.ftl,然后freemarker解析器将处理该视图.但是,如果JSP解析器能够找到文件并对其进行解析,那么freemaker解析器将不会用于解析该视图

ex: Since you have JSP and freemarker add the view resolvers for both and give the order property 1 for JSP and 2 for freemarker. If your view is /freemarker/hello.ftl then the JSP resoplver will fails since it will not be able to find th file /freemarker/hello.ftl, then the freemarker resolver will handle this view. But if the JSP resolver is able to find the file and resolve it then freemaker resolver will not be used to resolve that view

引用: 查看全文

登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆