Springboot Thymeleaf模板的使用(十)

Thymeleaf概述

1,Thymeleaf是一个现代服务器端Java模板引擎,适用于Web和独立环境,能够处理HTML,XML,JavaScript,CSS甚至纯文本。它的主要目标是提供一种优雅且高度可维护的模板创建方式。

Thymeleaf的基本语法说明

0,创建项目引入thymeleaf的依赖

		<dependency>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-starter-thymeleaf</artifactId>
		</dependency>

1,使用Thymeleaf 标签 之前需要引入<html xmlns:th="http://www.thymeleaf.org">。
如:

<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
  <head>
    <title>Good Thymes Virtual Grocery</title>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    <link rel="stylesheet" type="text/css" media="all" 
          href="../../css/gtvg.css" th:href="@{/css/gtvg.css}" />
  </head>
  <body>
    <p th:text="#{home.welcome}">Welcome to our grocery store!</p>
  </body>
</html>

2,如果我们希望获取到有未转义的数据使用:( th:utext对于“未转义的文本”),

例如:<p th:utext="#{home.welcome}">Welcome to our grocery store!</p>
结果:<p>Welcome to our <b>fantastic</b> grocery store!</p>

3,<p>Today is: <span th:text="${today}">13 February 2011</span></p>
${today}中存在数值的时候,会替代"13 February 2011"值。


4,消息和变量表达式:如下

<p th:utext="#{home.welcome}">Welcome to our grocery store!</p>
<p>Today is: <span th:text="${today}">13 february 2011</span></p>

5,准表达式功能:
简单表达:
变量表达式: ${...}
选择变量表达式: *{...}
消息表达式: #{...}
链接网址表达式: @{...}
片段表达式: ~{...}


字面:
文本:'one text','Another one!',...
数字:0,34,3.0,12.3,...
布尔:true,false
空字符: null
文字标记:one,sometext,main,...


文字操作:
字符串连接: +
字面替换: |The name is ${name}|


算术运算:
二元运算符:+,-,*,/,%
减号(一元运算符): -


布尔运算:
二元运算符:and,or
布尔否定(一元运算符): !,not


比较和平等:
比较:>,<,>=,<=(gt,lt,ge,le)
平等࿱

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值