使用spring boot + thymeleaf 做前台页面
一、th简单表达式
1. ${...} 变量表达式
<input type="text" name="userName" value="Beyrl" th:value="${user.name}" />
上述代码为引用user对象的name属性值
2. *{...} 选择表达式
<div th:object="${session.user}">
<p>Nationality: <span th:text="*{nationality}">XXXX</span>.</p>
</div>
选择表达式一般跟在th:object后 这是获取session里边的user
th:text后获取的是user里边的属性名
3. #{...} 消息文字表达式
<p th:utext="#{home.welcome}">Welcome to our grocery store!</p>
获取的是实体类的属性值
4. @{...} 链接url表达式
<a href="details.html" th:href="@{/webPage/details(orderId=${o.id})}">view</a>
@{...}支持绝对路径和相对路径。其中相对路径又支持上下文调用url和协议的引用
当URL为后台传入的参数时,代码如下
<img src="../../webPage/food/images/pizza.jpg" th:src="@{${path}}" alt="披萨" />
5.文字
文字:'one text' , 'another text'
数字: 1,2
布尔: true,false
空值: null
6.文本操作
链接:+
替换:|The name is ${name}|
<a href="" th:href="@{|/name/${test.size()}|}">链接地址:</a>
//渲染后的结果
<a href="/name/3">链接地址:</a>
7.数字操作
二元操作:+,-,*,/,%
一元操作:-(负)
8.布尔操作
一元:and or
二元:!,not
9.比较
比较:>,<,>=.<=(gt,lt,ge,le)
等于:==,!=(eq,ne)
10.条件
if-then:(if)?(then)
if-then-else:(if)?(then):(else)
default:(value)?:(defaultvalue)
关键字 | 功能介绍 |
---|