MUEAS项目,web前端采用thymeleaf作为展示层。这个view解析器,个人觉得非常不错。简单而且性能也比较好!个人觉得比JSP和freemarker之类,简单易用!

今天简单记录一下fragment的使用,这个类是JSP的tag,但是确非常简单。直接在html文件中,将自己觉得可能在多个地方出现的元素块用fragment包起来!

例如:

 <!DOCTYPE html>
<html>
<head>
...
</head>
<body>
<div th:fragment="footer">
&copy; 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">&copy; 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>

是不是很简单易用?我觉得很不错!

thymeleaf之fragment的更多相关文章

  1. thymeleaf的fragment例子

    fragment介绍 fragment类似于JSP的tag,在html中文件中,可以将多个地方出现的元素块用fragment包起来使用. 定义fragment 新建foot.html文件 <!D ...

  2. spring boot:thymeleaf给fragment传递参数的方法(spring boot 2.3.3)

    一,thymeleaf如何给fragment传递参数? 1,如果是全局的参数,可以用interceptor中传递 非全局参数,可以从controller中传递 2,引用片断时也可以传递参数 说明:刘宏 ...

  3. Thymeleaf+Spring整合

    前言 这个教程介绍了Thymeleaf与Spring框架的集成,特别是SpringMvc框架. 注意Thymeleaf支持同Spring框架的3.和4.版本的集成,但是这两个版本的支持是封装在thym ...

  4. SPRING + THYMELEAF 配置

    1.使用的是Spring EL而不是Ognl.2.访问上下文的Bean用${@myBean.doSomething()}3.th:field,th:errors,th:errorclass用于form ...

  5. thymeleaf 专题

    Thymeleaf 之 内置对象.定义变量.URL参数及标签自定义属性 如标题所述,这篇文章主要讲述Thymeleaf中的内置对象(list解析.日期格式化.数字格式化等).定义变量.获取URL的参数 ...

  6. spring+thymeleaf实现表单验证数据双向绑定

    前言 这个教程介绍了Thymeleaf与Spring框架的集成,特别是SpringMvc框架. 注意Thymeleaf支持同Spring框架的3.和4.版本的集成,但是这两个版本的支持是封装在thym ...

  7. Thymeleaf模板引擎+Spring整合使用方式的介绍

    尊重原创,原文地址为:https://www.cnblogs.com/jiangchao226/p/5937458.html 前言 这个教程介绍了Thymeleaf与Spring框架的集成,特别是Sp ...

  8. springboot thymeleaf【转】【补】

    thymeleaf模板 https://www.thymeleaf.org/doc/tutorials/3.0/usingthymeleaf.html 1.引入thymeleaf依赖 <!-- ...

  9. Springboot:thymeleaf模板(八)

    存放位置:resources\templates 访问方式:通过Controller请求访问,不可直接访问(相当于web项目的WEB-INF目录) 环境依赖: <!--thymeleaf模板支持 ...

随机推荐

  1. Use XML in Windows Phone 8.0

    I have an XML file stored in DataModel folder, the structure is shown as below: <?xml version=&qu ...

  2. magento memcache缓存配置

    在app/etc/local.xml <global>配置段中添加 cache段配置 <config> <global> <install> <d ...

  3. explicit用法

    explicit用来防止由构造函数定义的隐式转换. 要明白它的作用,首先要了解隐式转换:可以用单个实参来调用的构造函数定义了从形参类型到该类类型的一个隐式转换. 例如: class things { ...

  4. BLP模型

    编号:1002时间:2016年3月29日16:24:33功能:多级安全BLP模型 URL:http://blog.csdn.net/longronglin/article/details/150033 ...

  5. web程序调试方法

    1.火狐浏览器查看链接指向的后台方法(controller方法) f12 进入firebug 点击bug旁边的按钮 即第一排第二个按钮 将鼠标划到想要找的链接 在firebug中显示响应的后台跳转.d ...

  6. TC Hash Filter

    Overview The u32 filter allows you to match on any bit field within a packet, so it is in some ways ...

  7. 刻通云KeyTone Cloud测试

    注:本文转自陈沙克的博客,原文见http://www.chenshake.com/carved-through-the-keytone-cloud-cloud-testing/ 一直都很希望有更多的O ...

  8. java 代码分析工具——JDepend

    最近学习Mybatis的官方文档,看到了[项目文档]一节有很多内容没有见过,做个笔记,理解一下. 百科上的介绍,我竟然都看懂了,那就不找其他地方的资料了. JDepend 一个开放源代码的可以用来评价 ...

  9. 解决一台机器同时运行多个Tomcat服务

    http://www.cnblogs.com/itolssy/archive/2008/09/09/1278041.html 如果不加任何修改,在一台服务器上同时运行两个Tomcat服务显然会发生端口 ...

  10. [转载] TCP与UDP对比

    TCP和UDP区别     TCP UDP 是否连接 面向连接 面向非连接 传输可靠性 可靠的 不可靠的 应用场合 传输大量的数据 少量数据 速度 慢 快     OSI 和 TCP/IP 模型在传输 ...