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