记录一下今天使用th:include遇到的路径问题bug。
html目录结构:

backstage/common/common.html公共模块:
<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<nav th:fragment="sidebar">
</nav>
</html>在backstage/user/list.html引用common.html公共页面模块:
错误示范:
<div th:insert="~{common/common::sidebar}"/><div th:insert="~{/backstage/common/common::sidebar}"/>由于springboot templates是直接从根目录开始访问的,所以不能直接走common文件夹,也不用自己用/回到根目录。
正确示范:
<div th:insert="~{backstage/common/common::sidebar}"/>版权声明:本文为qq_46418539原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。