1、先创建一个需要被引用的html页面,在页面里面不需要放公共的css、js,只需要写一些html片段即可,但是需要在外层html添加上th:fragment属性,如下所示:
<div th:fragment="common_top"> <ul> <li></li> <li></li> </ul> <div>
2、然后在主页面通过th:replace属性进行引用,如下所示:
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Title</title> </head> <body> <div th:replace="html/common_top :: common_top"></div> </body> </html>
注意:被引用页面名称为common_top.html,需要在和主页面同级的html文件夹下