thymeleaf引入模板页面
2022-08-03 09:57:03
103
{{single.collect_count}}

通常我们一个网站页面的头部和底部都是相同的,我们不可能在每个页面都写相同的内容,一般都会将这些相同的写成模板在需要的页面引入即可。
demo开始:
写一个通用的底部:
起名为:footer.html
内容为:

<!DOCTYPE html><html lang="en" xmlns:th="http://www.thymeleaf.org"><footer th:fragment="common"><div class="foot-mes"><div><p>Copyright ©XXXXXXX有限公司 All Rights Reserved 苏ICP备101dsf0号</p><p>公司地址:XXXXXXXXXXXX 联系电话:00000000000</p></div></div></footer></html>

这个就相当于一个id

然后在index.html页面中引入这个页面

<!--footer--><div th:include="footer :: common"></div><!-- <div th:replace="footer :: common"></div> -->

th:include 和 th:replace区别,include只是加载,replace是替换
文件名和标签名要相同,不然会报错

回帖
全部回帖({{commentCount}})
{{item.user.nickname}} {{item.user.group_title}} {{item.friend_time}}
{{item.content}}
{{item.comment_content_show ? '取消' : '回复'}} 删除
回帖
{{reply.user.nickname}} {{reply.user.group_title}} {{reply.friend_time}}
{{reply.content}}
{{reply.comment_content_show ? '取消' : '回复'}} 删除
回帖
收起
没有更多啦~
{{commentLoading ? '加载中...' : '查看更多评论'}}