Thymeleaf 使用指南

Thymeleaf是一个现代的服务器端Java模板引擎,适用于Web和独立环境,能够处理HTML,XML,JavaScript,CSS甚至纯文本。

官方文档:Tutorial: Using Thymeleaf

中文文档:10.属性优先权 · Using Thymeleaf 译文

内置工具对象文档:Tutorial: Using Thymeleaf

 基础用法:

${x} will return a variable x stored into the Thymeleaf context or as a request attribute

${param.x} will return a request parameter called x (which might be multivalued).

${session.x} will return a session attribute called x.

${application.x} will return a servlet context attribute called x

基本的表达式对象:

#ctx: the context object.

#vars: the context variables.

#locale: the context locale.

#request: (only in Web Contexts) the HttpServletRequest object.

#response: (only in Web Contexts) the HttpServletResponse object.

#session: (only in Web Contexts) the HttpSession object.

#servletContext: (only in Web Contexts) the ServletContext object.

表达式公共对象

  • #execInfo: information about the template being processed.
  • #messages: methods for obtaining externalized messages inside variables expressions, in the same way as they would be obtained using #{…} syntax.
  • #uris: methods for escaping parts of URLs/URIs
  • #conversions: methods for executing the configured conversion service (if any).
  • #dates: methods for java.util.Date objects: formatting, component extraction, etc.
  • #calendars: analogous to #dates, but for java.util.Calendar objects.
  • #numbers: methods for formatting numeric objects.
  • #strings: methods for String objects: contains, startsWith, prepending/appending, etc.
  • #objects: methods for objects in general.
  • #bools: methods for boolean evaluation.
  • #arrays: methods for arrays.
  • #lists: methods for lists.
  • #sets: methods for sets.
  • #maps: methods for maps.
  • #aggregates: methods for creating aggregates on arrays or collections.
  • #ids: methods for dealing with id attributes that might be repeated (for example, as a result of an iteration).

控制块

1

引入片段

th:insert th:replace

2

迭代片段

th:each

3

条件评估

th:if th:unless th:switch th:case

4

局部变量定义

th:object th:with

5

一般属性修改

th:attr th:attrprepend th:attrappend

6

特殊属性修改

th:value th:href th:src ...

7

文本(标签体修改)

th:text th:utext

8

片段规格

th:fragment

9

片段删除

th:remove

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

83Dillon

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值