yml配置
spring:
resources:
chain:
strategy:
content:
enabled: true
paths: /**
cache: true
compressed: false
enabled: true
cache:
cachecontrol:
cache-public: true
增加代码配置
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.servlet.resource.ResourceUrlProvider;
@ControllerAdvice
public class ControllerConfig {
@Autowired
ResourceUrlProvider resourceUrlProvider;
@ModelAttribute("urls")
public ResourceUrlProvider urls() {
return this.resourceUrlProvider;
}
}
修改静态文件引入fangshi
<link rel="stylesheet" href="${urls.getForLookupPath('/css/index/index.css')}">
不足之处
只能对通过controller进入的页面生效,拦截器直接跳转的页面无效(跳转到页面的URL然后通过controller进入页面是有效的,直接进入页面是无效的)
当前版本
- Spring Boot 5.1.5.RELEASE