thymeleaf之fragment
2015-12-31 10:20
369 查看
MUEAS项目,web前端采用thymeleaf作为展示层。这个view解析器,个人觉得非常不错。简单而且性能也比较好!个人觉得比JSP和freemarker之类,简单易用!
今天简单记录一下fragment的使用,这个类是JSP的tag,但是确非常简单。直接在html文件中,将自己觉得可能在多个地方出现的元素块用fragment包起来!
例如:
在使用的地方,再用include标签将其引入即可!
例如:
注意:th:fragment定义的片段,在需要的地方,可以用th:include或者th:replace进行带入!
还有,所有的fragment可以写在一个文件里面,也可以单独存在。可以是一个html文件中的一部分。只要你需要,带上th:fragment的标签进行定义,让其为一个fragment即可。有点需要注意的是,片段所在的文件的路径,要用“/”分开路径,根路径为templates所在的路径。
比如:
是不是很简单易用?我觉得很不错!
今天简单记录一下fragment的使用,这个类是JSP的tag,但是确非常简单。直接在html文件中,将自己觉得可能在多个地方出现的元素块用fragment包起来!
例如:
<!DOCTYPE html> <html> <head> ... </head> <body> <div th:fragment="footer"> © 2013 Footer </div> </body> </html>
在使用的地方,再用include标签将其引入即可!
例如:
<!DOCTYPE html> <html> <head> <!--/* Each token will be replaced by their respective titles in the resulting page. */--> <title layout:title-pattern="$DECORATOR_TITLE - $CONTENT_TITLE">Task List</title> ... </head> <body> <!--/* Standard layout can be mixed with Layout Dialect */--> <div th:replace="fragments/header :: header"> ... </div> <div class="container"> <div layout:fragment="content"> <!-- ============================================================================ --> <!-- This content is only used for static prototyping purposes (natural templates)--> <!-- and is therefore entirely optional, as this markup fragment will be included --> <!-- from "fragments/header.html" at runtime. --> <!-- ============================================================================ --> <h1>Static content for prototyping purposes only</h1> <p> Lorem ipsum dolor sit amet, consectetur adipiscing elit. Praesent scelerisque neque neque, ac elementum quam dignissim interdum. Phasellus et placerat elit. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Praesent scelerisque neque neque, ac elementum quam dignissim interdum. Phasellus et placerat elit. </p> </div> <div th:replace="fragments/footer :: footer">© 2014 The Static Templates</div> </div> </body> </html>
注意:th:fragment定义的片段,在需要的地方,可以用th:include或者th:replace进行带入!
还有,所有的fragment可以写在一个文件里面,也可以单独存在。可以是一个html文件中的一部分。只要你需要,带上th:fragment的标签进行定义,让其为一个fragment即可。有点需要注意的是,片段所在的文件的路径,要用“/”分开路径,根路径为templates所在的路径。
比如:
<body> <div class="container"> <div th:include="exam/special/geeker/geeker::geeker-base-header"></div> <div class="geeker-content"> <div th:include="exam/special/geeker/geeker::geeker-base-left"></div> <div class="geeker-main"> </div> <div class="geeker-right"> </div> </div> </div> </body>
是不是很简单易用?我觉得很不错!
相关文章推荐
- httpd.conf
- jquery正则表达式验证(手机号、身份证号、中文名称)
- 集合操作符
- 计算机图形学 :中点画圆法
- vector中的erase用法注意事项
- *在Win7中安装JDK1.7并配置环境变量
- 2015 最后一日 公瑾
- 2015:开源软件引爆了这一年
- 零编程经验的我是如何找到工作的
- leetcode第6题——*ZigZag Conversion
- 1129ForForTest2
- 1129ForForTest
- 值得多逛逛的技术网站
- 我的Mybatis基本配置
- 解决Plugin is too old,please update to a more recent version,or set ANDROID_DAILY_OVERRIDE..
- hbase笔记
- 解决Plugin is too old,please update to a more recent version,or set ANDROID_DAILY_OVERRIDE..
- ExecuteReader方法
- log4cxx
- 8、多态详解