项目结构:
配置文件
#动态资源搜索路径
spring.thymeleaf.prefix=classpath:/templates/thymeleaf
#静态资源搜索路径
spring.resources.static-locations=classpath:/META-INF/resources/,classpath:/resources/, classpath:/static/, classpath:/public/, file:D:/upload/
被引入的模板:
<div th:fragment="fragment名">
例如
<div th:fragment="myfooter"/>
主页面(主动引入的页面)
<div th:replace="动态资源路径::fragment名">
例如
<div th:replace="/common/footer::myfooter"/>
另外还有一个命令:th:include
th:include 和 th:replace区别,include只是加载,replace是替换,替换内容包括<div th:replace>
也一起替换,而include会将内容加载到<div th:include>
里面