thymeleaf之fragment
来源:互联网 发布:android源码分析 编辑:程序博客网 时间:2024/05/16 06:58
MUEAS项目,web前端采用thymeleaf作为展示层。这个view解析器,个人觉得非常不错。简单而且性能也比较好!个人觉得比JSP和freemarker之类,简单易用!
今天简单记录一下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>
阅读全文
0 0
- thymeleaf之fragment
- thymeleaf中的fragment使用
- Thymeleaf 之 简要概述
- Thymeleaf 之 HelloWorld
- Thymeleaf 之 初步使用
- thymeleaf中fragment 的layout布局
- using thymeleaf之三文字
- using thymeleaf之十一内联
- Thymeleaf 之 页面模板应用
- Spring Boot 12之 thymeleaf
- SpringBoot之thymeleaf(Q)
- springboot之模板引擎 --- thymeleaf
- springboot入门之Thymeleaf篇
- springboot web入门之Thymeleaf
- Spring Boot 系列之 thymeleaf
- Thymeleaf
- thymeleaf
- thymeleaf
- 日常
- 有意思的智力题
- 念
- Delphi Tokyo 版本 TWebBrowser 的一个问题(Bug?)
- 理解 Python 中的 *args 和 **kwargs
- thymeleaf之fragment
- 【学习笔记】Python
- C语言实验——买糖果
- Selenium Webdriver元素定位的八种常用方式详解
- 大话设计模式之职责链模式
- concurrentHashMap
- MySQL的禁止删除触发器
- servlet之路径问题
- leetcode102. Binary Tree Level Order Traversal & 103. Zigzag Level