spring mvc:显示特定于国家/地区的视图,如果不存在则显示默认视图
情况:我有一个应用程序,它为每个特定国家/地区使用单独的jsp文件(我已经使用视图解析器实现了)。然而,使用这种方法,即使该页面没有特定的更改,我也必须对每个国家/地区重复 jsp 更改。
示例:对于“en”主题的用户,我的发票页面与“de”主题的用户不同,具有不同的布局和不同的逻辑。转到相同的控制器并根据用户具有不同的操作。
但大多数时候逻辑和 jsp 页面是相同的(例如帐户列表)。
问题:如何保留此逻辑并为该特定操作创建后备页面?如果存在 /de/invoice.jsp 就使用它,否则使用 /invoice.jsp(就像 drupal 中的主题)
我使用tomcat作为应用程序服务器。
有什么建议吗?
(请注意,我所说的“主题”并不是指 Spring 对主题的支持,而是一般问题可以通过 Spring 的主题来解决。)
situation:I have an application that uses separate jsp files for each specific country(I've implemented with view resolver). However with this approach I have to repeat the jsp changes for each country even if there is no specific change for that page.
example: for users of "en" theme I have different invoice page than users of "de" theme with different layout and different logic. Goes to same controller and has different actions according to user.
but most of the time the logic and the jsp page is same (for example listing of accounts).
question:How can keep this logic and also make a fallback page for that specific action? If exists /de/invoice.jsp just use this else use /invoice.jsp(just like the themes in drupal)
I use tomcat as application server.
Any suggestion?
(Please note that by "theme" I do not mean Spring's support for themes, but rather the general problem can be solved with Spring's themes.)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
基本上,您只想动态选择
的页面。假设您将页面名称包含在名为“invoicePage”的变量中。然后,视图解析器中引用的页面模板可以包含该变量,如下所示:
因此,唯一的技巧是选择正确的发票页面。
Spring 主题对此有一个很好的解决方案:将特定于主题的包含名称放入特定于主题的属性文件中,Spring 将负责为您回退到默认值。
或者,您可以实现自己的配置,可能基于列出具有特定内容的国家/地区或在每个国家/地区设置指标的配置。哪种解决方案合适取决于您如何配置应用程序的其余部分。
Basically you just want to pick the page of a
<jsp:include>
dynamically.Let's assume that you put the page name to include in a variable called "invoicePage". Then, the page template that's referenced in your view resolver can include that variable as follows:
So, the only trick is picking the right invoicePage.
Spring themes have a nice solution to this: put the name of the theme-specific include in your theme-specific properties file, and Spring will take care of falling back to the default for you.
Alternatively you can implement your own, probably based on a configuration that either lists countries with specific content or that sets an indicator on a per country basis. Which solution is appropriate depends on how you've configured the rest of your app.