默認情況下,Spring Boot 從類路徑中的/static (或/public 或/resources 或/META-INF/resources)目錄.訪問 : 當前項目根路徑/ + 靜態資源名
原理: 靜態映射/**。請求進來,先去找Controller看能不能處理。不能處理的所有請求又都交給靜態資源處理器。靜態資源也找不到則響應404頁面
改變默認的靜態資源路徑:
spring:
mvc:
static-path-pattern: /res/**
resources:
static-locations: [classpath:/haha/]
static-path-patten:/res/** 是靜態資源要訪問的真實路徑
static-location: [classpath:/haha/]是將這些靜態資源都放在指定文件夾下面方便后面的攔截器的操作
當前項目 + static-path-pattern + 靜態資源名 = 靜態資源文件夾下找