![在这里插入图片描述 【Spring Boot】template: “class path resource [templates/admin/main.html]“_项目结构](https://file.cfanz.cn/uploads/png/2022/08/12/2/eL7cAZa777.png)
今天使用SpringBoot做项目的时候,处理公共页面抽取的时候,出现了上面的错误,搞了好半天,最后发现是路径的问题,代码主要如下:
![在这里插入图片描述 【Spring Boot】template: “class path resource [templates/admin/main.html]“_html_02](https://file.cfanz.cn/uploads/png/2022/08/12/2/17b20115d1.png)
![在这里插入图片描述 【Spring Boot】template: “class path resource [templates/admin/main.html]“_spring_03](https://file.cfanz.cn/uploads/png/2022/08/12/2/23HQ7P3OcV.png)
项目结构:
![在这里插入图片描述 【Spring Boot】template: “class path resource [templates/admin/main.html]“_spring boot_04](https://file.cfanz.cn/uploads/png/2022/08/12/2/Q6286ZY087.png)
在使用thymeleaf 导入公共部分的时候,最初写法:
<div th:include="common :: common_head"></div>
但是默认是到templates目录下找common.html公共页面,而我又创建了一级admin目录,所以默认去找根本找不到,需要改成下面的样式,在指定common的时候添加前级目录:
<div th:include="~{/admin/common :: common_head}"></div>
