SpringBoot整合thymeleaf导入HTML文件
目录
1、准备HTML相关文件(包括HTML和相关css,js文件)
模板网站:www.themezy.com
onepagelove.com
free-css.com
2、新建springboot项目,利用maven导入thymeleaf依赖
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
3、资源文件如图所示放置
原理:基于thymeleaf的模板引擎在默认配置下,url栏输入localhost:8080
,会自动扫描templates文件夹,并找到index.html文件。
HTML文件中语句可能如下所示:
<link href="../static/fonts/font-awesome.min.css" rel="stylesheet" type="text/css">
这种情况下,跑项目时这句代码会404,因为springboot找静态资源,默认在static等四个文件夹里自动搜索,不需要加入../static
正确语句为<link href="fonts/font-awesome.min.css" rel="stylesheet" type="text/css">
修改后即可加载