添加Thymeleaf依赖
1 | <dependency> |
Spring Boot默认存放模板页面的路径在src/main/resources/templates
在<html>
标签中引入:
1 | <html xmlns:th="http://www.thymeleaf.org"> |
条件语句 th:if
1 | <li th:if="${session.user != null}"> |
迭代器 th:each
遍历questions集合
1 | <div class="media" th:each="question:${questions}"> |
图片地址 th:src
1 | <a href="#"> |
文本显示 th:text
1 | <span th:text="${#dates.format(question.gmtCreate,'yyyy.MM.dd')}"></span> |
th:value
用来页面回显
1 | <div class="form-group"> |
部分后台代码
1 | "/publish") ( |
<textarea>
标签里的回显问题:要用th:text
才起作用,th:value
不起作用 不懂为什么??
设置样式 th:class
1 | <li th:class="${pagination.page==page}? 'active' : ''"> |
链接拼接 th:href
1 | <a th:href="@{/(page=${page})}" th:text="${page}"></a> |
1 | <a th:href="@{'/profile/'+${section}(page=${2})}" aria-label="Previous"> |
引用片段 th:insert
在/templates
目录下新建一个名为navigation.html
的文件,内容是:
1 |
|
使用(在页面中引入)
1 | <body> |
以上是做项目过程中用到的部分Thymeleaf知识点