1.表达式
1、 标准变量表达式
A:${....} 获取上下文,取model中的数据,动态请求数据、
eg:<span th:text="${name}"></span>,获取后端传回名为name的数据
B:#{....} 获取静态数据,如果使用配置文件,配置文件的默认名称为messages.properties
eg:<span th:text="#{name}"></span>,获取messages配置文件的键值对数据
2、选择变量表达式
*{....} 获取动态数据,不过需要先绑定数据然后获取其属性,使用th:object
eg:<p th:object="${user}"><span th:text="*{userName}"></p>
3、URL表达式
A:@{/....}用于定义URL,定义根目录下,使用相对路径解决了路径错位
eg:<link rel="stylesheet" th:href="@{/layui/css/public.css}" media="all">
B:使用URL表达式能在表达式拼接字符串
eg:<a th:href="@{'/user/'+${username}}"> <=等同于=> <a th:href="@{|/user/${username}|}">
2.相关属性
注:
使用需要在头部html标签中添加声明:xmlns:th="http://www.thymeleaf.org"
eg: