thymeleaf

官方网站:http://www.thymeleaf.org/html

 thymeleaf简介git

 Thymeleaf 是一个跟 Velocity、FreeMarker 相似的模板引擎,它能够彻底替代 JSP 。相较与其余的模板引擎,它有以下三个极吸引人的特色:程序员

    1.Thymeleaf 在有网络和无网络的环境下皆可运行,即它能够让美工在浏览器查看页面的静态效果,也能够让程序员在服务器查看带数据的动态页面效果。这是因为它支持 html 原型,而后在 html 标签里增长额外的属性来达到模板+数据的展现方式。浏览器解释 html 时会忽略未定义的标签属性,因此 thymeleaf 的模板能够静态地运行;当有数据返回到页面时,Thymeleaf 标签会动态地替换掉静态内容,使页面动态显示。github

    2.Thymeleaf 开箱即用的特性。它提供标准和spring标准两种方言,能够直接套用模板实现JSTL、 OGNL表达式效果,避免天天套模板、改jstl、改标签的困扰。同时开发人员也能够扩展和建立自定义的方言。web

    3. Thymeleaf 提供spring标准方言和一个与 SpringMVC 完美集成的可选模块,能够快速的实现表单绑定、属性编辑器、国际化等功能。spring

表达式浏览器

变量表达式"${  }" 服务器

<span th:text="${book.author.name}">

消息表达式"#{  }" 网络

<span th:text="#{book.author.name}">

(文本外部化、国际化、i18n)app

选择表达式"*{  }" 

<div th:text="${book}">
    <span th:text="*{name}"></span>
</div>

连接表达式 "@{  }"

<a th:href="@{../doucments/report}">...</a>
<a th:href="@{~/doucments/report}">...</a>
<a th:href="@{//static.mycompany.com/report}">...</a>
<a th:href="@{http://www.mycompany.com/doucments/report}">...</a>

分段表达式 th:insert th:replace

<!doctype html>
<html xmls:th="http://www.thymeleaf.org">
    <body>
        <div th:fragment="copy">
            &copy; 2017 <a href="https//waylau.com">waylau.com</a>
    </body>
</html>
<body>
    ...
    <div th:insert="~{foot :: copy }"></div>
</body>

字面量

文本

<p>
    Now you are looking at a <span th:text="'working web application'">template file</span>.
</p>

数字

<p>
    The year is <span th:text="2013">1492</span>.
</p>

布尔 true、false

空 null

算术操做

+、-、*、/、%

比较:>、<、>=、<=(gt、lt、ge、le)

等价 :==、!= (eq ne)

三目运算符 ? :

无操做 _

字面量(文字)

null

<div th:if="${variable.something} ==null"></div>

 

参考资料:https://github.com/waylau/thymeleaf-tutorial

相关文章
相关标签/搜索