用thymeleaf写一个博客首页页面
时间: 2023-11-30 22:12:13 浏览: 102
好的,我可以给您提供一个thymeleaf写的博客首页页面的示例,您可以根据自己的需求进行修改。
```
<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
<meta charset="UTF-8">
<title>博客首页</title>
</head>
<body>
<div th:replace="fragments/header :: header"></div>
<div class="container">
<div class="row">
<div class="col-md-8">
<h2>最新文章</h2>
<div th:each="article : ${articles}" class="article">
<h3 th:text="${article.title}"></h3>
<p th:text="${article.summary}"></p>
<a th:href="@{/article/{id}(id=${article.id})}">阅读更多</a>
</div>
</div>
<div class="col-md-4">
<h2>热门文章</h2>
<div th:each="article : ${hotArticles}" class="article">
<h3 th:text="${article.title}"></h3>
<p th:text="${article.summary}"></p>
<a th:href="@{/article/{id}(id=${article.id})}">阅读更多</a>
</div>
</div>
</div>
</div>
<div th:replace="fragments/footer :: footer"></div>
</body>
</html>
```
这个页面使用了thymeleaf的语法,其中`fragments/header`和`fragments/footer`是引用了其他页面中定义的header和footer,可以用来避免重复代码的编写。页面中展示了最新文章和热门文章,使用了`th:each`指令来循环展示每个文章的标题、摘要和阅读更多的链接,这些数据来源于`articles`和`hotArticles`这两个变量,需要在控制器中注入并赋值。
阅读全文
相关推荐
![-](https://img-home.csdnimg.cn/images/20210720083447.png)
![-](https://img-home.csdnimg.cn/images/20241231045053.png)
![-](https://img-home.csdnimg.cn/images/20241231045053.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![rar](https://img-home.csdnimg.cn/images/20241231044955.png)
![-](https://img-home.csdnimg.cn/images/20241231045053.png)
![-](https://img-home.csdnimg.cn/images/20241231045053.png)
![-](https://img-home.csdnimg.cn/images/20241231045053.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![-](https://img-home.csdnimg.cn/images/20241231045053.png)
![-](https://img-home.csdnimg.cn/images/20241231045053.png)
![-](https://img-home.csdnimg.cn/images/20241231045053.png)