Java Spring MVC Web 应用程序中的模板
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/19347181/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Templates in a Spring MVC web application
提问by MChan
I have a lot of common areas in my web application design, for example footer, header sidebar, blocks...etc and going through all of the application JSP files to change something for example in the header is pretty hectic so I was wondering if I can make something like template files for common areas for example header template, sidebar template, footer template, then I can include such templates in any JSP inside my application?
我的 Web 应用程序设计中有很多公共区域,例如页脚、页眉侧边栏、块...等,并且浏览所有应用程序 JSP 文件以更改例如页眉中的某些内容非常忙碌,所以我想知道是否我可以为公共区域制作类似模板文件的东西,例如页眉模板、侧边栏模板、页脚模板,然后我可以在我的应用程序中的任何 JSP 中包含这些模板吗?
I am using Spring MVC framework to build my application
我正在使用 Spring MVC 框架来构建我的应用程序
采纳答案by Jk1
As for templating you have the following options:
至于模板,您有以下选择:
Custom JSP tags. These tags may exist as Java classes or JSP snippets and provide a basic facility to encapsulate and reuse parts of JSP pages (headers, footers, etc.). See more in this manual
Template engines like Tilesor decorators like Sitemesh. They are quite powerfull in building complex page layouts.
自定义 JSP 标记。这些标签可能作为 Java 类或 JSP 片段存在,并提供了一种基本工具来封装和重用 JSP 页面的部分(页眉、页脚等)。在本手册中查看更多信息
If you're looking for custom UI themes support please take a look at custom themes supportin Spring MVC.
如果您正在寻找自定义 UI 主题支持,请查看Spring MVC 中的自定义主题支持。
回答by Raja P
Ideally yes, You need to create common files instead of redundant code because it might leads to many changes if u want to change a single thing. So try to use below code based on your requirement.
理想情况下是的,您需要创建通用文件而不是冗余代码,因为如果您想更改单个内容,它可能会导致许多更改。因此,请尝试根据您的要求使用以下代码。
<%@ include is a static include, <jsp:include is a dynamic include.
<%@ include is a static include, <jsp:include is a dynamic include.
Another solution: As you are using Spring framework try to use spring tiles search in google for more help for example SpringByExample
另一个解决方案:当您使用 Spring 框架时,请尝试在 google 中使用 spring tile 搜索以获取更多帮助,例如SpringByExample
回答by Ralph
If you want to seperate Header, Footer and some other common stuff from the "real" content, then you can use Apache Tiles.
如果您想将页眉、页脚和其他一些常见内容与“真实”内容分开,那么您可以使用Apache Tiles。
It is easy to integrate in spring. So for example Spring Roo use it.
在 spring 中很容易集成。因此,例如 Spring Roo 使用它。
回答by pappu_kutty
I have used Apache Tiles. It can be very easily integrated with Spring MVC. You can also consider using sitemesh. As you mentioned header template, footer template you can have base template for header, footer, menu and you can integrate them into base template,
我使用过 Apache Tiles。它可以很容易地与 Spring MVC 集成。你也可以考虑使用sitemesh。正如您提到的页眉模板、页脚模板,您可以拥有页眉、页脚、菜单的基本模板,并且可以将它们集成到基本模板中,
Note : You can only have jsp and not html here.
注意:这里只能有jsp,不能有html。
Check this link for spring with tiles.
检查此链接以获取带瓷砖的弹簧。
http://www.springbyexample.org/examples/dynamic-tiles-spring-mvc-module.html
http://www.springbyexample.org/examples/dynamic-tiles-spring-mvc-module.html