Springboot Thymeleaf如何正确导入静态资源?

2026-04-02 15:151阅读0评论SEO资源
  • 内容介绍
  • 文章标签
  • 相关推荐

本文共计260个文字,预计阅读时间需要2分钟。

Springboot Thymeleaf如何正确导入静态资源?

在Thymeleaf配置时,若遇到静态资源导入问题,检查pom配置:

1. 查看pom文件,确认是否已引入以下依赖: xml org.springframework.boot spring-boot-starter-thymeleaf

2. 若已引入,检查配置文件(如application.properties或application.yml)中静态资源路径设置是否正确。

3. 如果静态资源仍然无法加载,可能需要添加额外的配置或修改资源路径。

thymeleaf配置时产生的问题静态资源导入问题pom配置查看pom文件中是否引入thymeleaf

thymeleaf配置时产生的问题静态资源导入问题

pom配置

查看pom文件中是否引入thymeleaf

org.springframework.bootspring-boot-starter-thymeleaf

application.yml 配置

#关闭模板引擎的缓存spring.thymeleaf.cachefalse

springboot thymeleaf会有缓存问题可能会配置后不生效

Springboot Thymeleaf如何正确导入静态资源?

静态资源导入

项目目录的配置如下图 把项目导入进去css、js、images等等

创建index页面

在html页面头部中引入

xmlns:th"www.thymeleaf.org"

CSS引入

th有很多用法参考官方文档语法 这里配置时切记不用加/static/ !自动查找根目录 引入后还会遇到模板缓存问题所以**记得更新maven清除缓存**然后家可以导入css样式了jsimg同理。

本文共计260个文字,预计阅读时间需要2分钟。

Springboot Thymeleaf如何正确导入静态资源?

在Thymeleaf配置时,若遇到静态资源导入问题,检查pom配置:

1. 查看pom文件,确认是否已引入以下依赖: xml org.springframework.boot spring-boot-starter-thymeleaf

2. 若已引入,检查配置文件(如application.properties或application.yml)中静态资源路径设置是否正确。

3. 如果静态资源仍然无法加载,可能需要添加额外的配置或修改资源路径。

thymeleaf配置时产生的问题静态资源导入问题pom配置查看pom文件中是否引入thymeleaf

thymeleaf配置时产生的问题静态资源导入问题

pom配置

查看pom文件中是否引入thymeleaf

org.springframework.bootspring-boot-starter-thymeleaf

application.yml 配置

#关闭模板引擎的缓存spring.thymeleaf.cachefalse

springboot thymeleaf会有缓存问题可能会配置后不生效

Springboot Thymeleaf如何正确导入静态资源?

静态资源导入

项目目录的配置如下图 把项目导入进去css、js、images等等

创建index页面

在html页面头部中引入

xmlns:th"www.thymeleaf.org"

CSS引入

th有很多用法参考官方文档语法 这里配置时切记不用加/static/ !自动查找根目录 引入后还会遇到模板缓存问题所以**记得更新maven清除缓存**然后家可以导入css样式了jsimg同理。