thymeleaf中的th:insert

th:insert

thymeleaf模板的th:insert用法:

好处:公共的模块就不用每次都写,需要就拿来用。
例如下图,头部内容完全可以放入公共文件中。

thymeleaf中的th:insert
thymeleaf中的th:insert

头部代码一大堆,每个html文件都写一遍太麻烦。提取红框里的代码,放到另一个html文件中。

源文件只需要加入下图所示即可使用thymeleaf中的th:insert

foreign是我的文件夹,common是我这个文件夹下的html文件,#h代表添加id为h代码片段。

头部效果显示相同。