title: thymeleaf学习
date: 2019-11-22
原本在个人博客上写了一些博文,现转移到CSDN上
thymeleaf学习之fragment
在上一篇博客中,简单的介绍了一些thymeleaf的使用,包括thymeleaf如何利用modelandview确定view的名字以及如何给model加值。并利用确定好的model以及view在前台绑定与渲染数据。本篇博客将介绍如何利用fragment作为模板,在网页需要的地方,嵌入模板网页中写的指定的部分。
- 写模板网页
图片中
th:fragment="side"
side为与其他网页链接的关键词。
- 在其他网页中链接需要的div
<div th:replace="fragments/sidebar :: side"></div>
在这一句中,这个div将会被sidebar.html中的side这个div替换掉