最近在做项目时候用到了 layout布局的方式,相对方便了很多,记录一下.这个layout的效果是可以把网页的相同部分提取出来,只需要更改核心不一样的地方就可以了.也就是更改后边我们会提到的content
部分.
- 首先建立相同部分的html,这里我命名为layout.html,放在了`templates/layout'文件夹下,这个路径以后是会用到的,以下是我的layout的代码,比较粗糙.
但是应该会更好的帮助理解.
要提到几个重要的部分
- xmlns:th="http://www.thymeleaf.org" 引入th
- xmlns:layout="http://www.w3.org/1999/xhtml" 引入 thymeleaf
- <div layout:fragment="content"></div> 你要将不同内容放置的位置