如何根据不同的域确定spring-mvc不同的视图解析器?
我有一个 Spring-MVC 项目,需要有 2 个视图,例如:views/xxx/...views/yyy/...,我想知道如何根据域确定要使用哪个视图,例如:xxxcom, yyycom。
我知道如何制作一个InternalResourceViewResolver, <强>
但没有基于域的多个视图的线索。
I have a Spring-MVC project which needs to have 2 views for example: views/xxx/... views/yyy/..., I wondering how to determine which view i gonna use based on the domains for example: xxxcom, yyycom.
I know how to make one InternalResourceViewResolver,
but no clues for the multiple views based on the domains.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
根据您的具体问题,我不会使用基于域的不同视图,而是使用 Spring 的主题解析器来使用相同的视图,然后根据域更改该视图的不同部分。
然后,您可以根据所访问的域交换不同的样式和内容。
有关 Spring 主题解析器的更多信息:
http://static.springsource.org/spring/docs/3.0.x/spring-framework-reference/html/mvc.html#mvc-themeresolver
在了解了实现主题的方式后,您将只需编写一个主题解析器,根据用户访问的域解析主题属性文件。
当然,如果您需要不同领域的完全不同的视图,您可能需要稍微不同的解决方案。
Depending on your specific problem, rather than using different views based upon the domain I would go with Spring's Theme resolver to use the same views then change different parts of that view based upon the domain.
You can then swap out different bits of styling and content based upon the domain being visited.
For more information on the Spring theme resolver:
http://static.springsource.org/spring/docs/3.0.x/spring-framework-reference/html/mvc.html#mvc-themeresolver
After understanding the way to implement themes you would simply have to write a theme resolver that resolved the theme properties file based upon the domain the user has visited.
Of course if you need completely different views for the different domains you might need a slightly different solution.