请教一下springboot引入静态资源文件要做哪些配置?
1.完整yml文件配置
# 热部署
spring:
devtools:
restart:
enabled: true
additional-exclude: WEB-INF/**
# 配置静态资源文件路径
resources:
static-locations: ["/templates/","/resources/","/static/","/public/"]
# 配置数据库连接
datasource:
url: jdbc:mysql://localhost:3306/sakila?useUnicode=true&characterEncoding=utf-8&useSSL=false
username: root
password:
driver-class-name: com.mysql.jdbc.Driver
# redis配置
redis:
database: 0
host: localhost
port: 6379
password:
pool:
max-active: 8
max-wait: -1
max-idle: 8
min-idle: 0
timeout: 0
# 配置模版引擎
thymeleaf:
prefix: classpath:/templates/
suffix: .html
cache: false
mvc:
static-path-pattern: /**
# 配置端口号
server:
port: 8081
# 配置mybatis
mybatis:
mapper-locations: classpath:mappers/*.xml
2.页面引用静态资源如图所示
楼主,你在前面再加一个斜杠,就行了,我也遇到你的问题,我加斜杠解决了,你看我的截图:
昨天遇到同样的问题,你把css、js文件直接放在templates下面试试。
我快要疯了,web调试工具里面,所有静态资源都是200,请求成功,但是,css和js就是不生效,已经消耗了3个多小时了,接近崩溃,依然无从下手。
应该是你的ngix拦截了