可能是最全的Thymeleaf参考手册:终极篇,全,全,全!!!

Thymeleaf是一个现代的、服务器端的Java模板引擎,适用于Web和独立环境。其主要目标是为开发工作流程带来异常优雅的自然模板——可以再浏览器中正确显示HTML,也可以作为静态原型,使开发团队协作更通畅。

目前Thymeleaf已于Spring Framework集成,相信凭借Spring Framework的出色特性,能使Thymeleaf成为现代HTML5 JVM Web开发的首选。

Thymeleaf全部的参考手册如下:

 

另外,Thymeleaf还有其它官方的工具和扩展库。

 

Thymeleaf测试库


https://github.com/thymeleaf/thymeleaf-testing

Thymeleaf测试库允许开发人员以非常简单和声明性的方式为Thymeleaf应用程序和扩展创建自动测试。其功能包括:

  • 作为独立的库工作,可以从多个测试框架(例如JUnit)中调用
  • 仅测试视图层:模板处理及其结果。
  • 允许将测试输入指定为标记片段,也可以指定为正在开发的基于Thymeleaf的应用程序的模板文件的链接,以便轻松测试其视图层
  • 通用的测试工件:测试序列,迭代,并发执行...
  • Spring FrameworkSpring Security 集成。

测试规范可以这样简单:

%TEMPLATE_MODE HTML5
# ------------ separator comment -----------
%CONTEXT
onevar = "Goodbye,"
# ------------------------------------------
%MESSAGES
one.msg = Crisis
# ------------------------------------------
%INPUT
<!DOCTYPE html>
<html>
  <body>
    <span th:text="${onevar}">Hello,</span>
    <span th:text="#{one.msg}">World!</span>
  </body>
</html>
# ------------------------------------------
%OUTPUT
<!DOCTYPE html>
<html>
<body>
  <span>Goodbye,</span>
  <span>Crisis</span>
</body>
</html>

 

Thymeleaf Eclipse插件


https://github.com/thymeleaf/thymeleaf-extras-eclipse-plugin

用于Eclipse IDE的Thymeleaf插件添加了内容辅助功能,使在Thymeleaf模板中的工作变得更好,更舒适。

  • Thymeleaf属性处理器的 代码完成。
  • 每个属性的详细说明。
  • 表达式内的内容辅助:表达式实用程序对象

 

Thymeleaf + Spring Security


https://github.com/thymeleaf/thymeleaf-extras-springsecurity

Thymeleaf Extras Spring Security库提供了一种方言,可以将Spring Security的多个授权和身份验证方面(版本3.x,4.x和5.x)集成到基于Thymeleaf的应用程序中。特征:

  • 基于Thymeleaf的等效于Spring Security JSP的标签库
  • 添加新的表达式实用程序对象,例如 #authentication 和 #authorization,用于将Spring Security功能集成到Thymeleaf表达式中
  • 添加新的属性,例如 sec:authentication 和 sec:authorized以简化安全性配置。

使用此库,可以轻松使用Spring Security中定义的基于角色的访问限制:

<div sec:authorize="hasRole('ROLE_ADMIN')">
  This will only be displayed if authenticated user has role ROLE_ADMIN.
</div>

与安全性相关的对象也可以包含在普通的Thymeleaf表达式中:

<div th:text="${#authentication.name}">
  The value of the "name" property of the authentication object should appear here.
</div>

 

Thymeleaf + IE条件注释


https://github.com/thymeleaf/thymeleaf-extras-conditionalcomments

Thymeleaf Extras条件注释库为Thymeleaf模板中的Internet Explorer 条件注释提供了支持。

  • 在条件注释中 处理Thymeleaf 属性处理器
  • 支持条件注释的整个语法。

IE条件注释如下所示:

<!--[if lt IE 8]>
<link rel="stylesheet" th:href="@{/resources/blueprint/ie.css}"
  type="text/css" media="screen, projection">
<![endif]-->

并且由于有了这个库,它们可以像下面的代码一样正确执行:

<!--[if lt IE 8]>
<link rel="stylesheet" href="/myapp/resources/blueprint/ie.css"
  type="text/css" media="screen, projection">
<![endif]-->

另外,Thymeleaf用户在Thymeleaf项目之外开发和维护,并根据其自己的许可和支持条款进行分发。如Thymeleaf Layout DialectThymeleaf Cache Dialect、Data Attribute DialectThymeleaf Spring Data Dialect等,感兴趣的,可根据以下地址查看其相关信息。

Thymeleaf Layout Dialect

https://github.com/ultraq/thymeleaf-layout-dialect

Thymeleaf Cache Dialect

https://github.com/Antibrumm/thymeleaf-extras-cache-dialect

Data Attribute Dialect

https://github.com/mxab/thymeleaf-extras-data-attribute

Thymeleaf Spring Data Dialect

https://github.com/jpenren/thymeleaf-spring-data-dialect

 

 

 

回复以下关键字,获取更多资源

 

SpringCloud进阶之路 | Java 基础 | 微服务 | JAVA WEB | JAVA 进阶 | JAVA 面试 | MK 精讲

 


 

笔者开通了个人微信公众号【银河架构师】,分享工作、生活过程中的心得体会,填坑指南,技术感悟等内容,会比博客提前更新,欢迎订阅。

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值