springboot使用thymeleaf的方式引用static中的静态资源以及引用框架文件资源方法

一、实现:在springboot项目中通过使用thymeleaf的方式在前端的html页面中使用src/main/resources/static中的静态资源文件。

二、在src/main/resources/static中的静态资源文件目录结构如下图
springboot使用thymeleaf的方式引用static中的静态资源以及引用框架文件资源方法_第1张图片
1.在html页面中引入thymeleaf的依赖。如下

"en" xmlns:th="http://www.thymeleaf.org">

springboot使用thymeleaf的方式引用static中的静态资源以及引用框架文件资源方法_第2张图片
2.由于springboot框架中配置的资源文件路径默认到src/main/resources/static下,所以我们使用静态资源的路径在html中可以这么写,注意thymeleaf的对html标签属性的写法:

{/css/bootstrap.min.css}" rel="stylesheet">

springboot使用thymeleaf的方式引用static中的静态资源以及引用框架文件资源方法_第3张图片
3.同样的,图片也是同上的写法

{/img/bootstrap-solid.svg}" class="content"/>

springboot使用thymeleaf的方式引用static中的静态资源以及引用框架文件资源方法_第4张图片
4.同样的,js也是同样的方法


springboot使用thymeleaf的方式引用static中的静态资源以及引用框架文件资源方法_第5张图片

但是经测试发现:

{/css/bootstrap.min.css}" rel="stylesheet">

"/css/bootstrap.min.css" rel="stylesheet">

这两种都可以
在这里插入图片描述

你可能感兴趣的:(SpringBoot)