Spring Boot 對靜態資源映射提供了默認配置css
classpath:/static classpath:/public classpath:/resources classpath:/META-INF/resources
http://localhost:8080/a.jpg http://localhost:8080/b.jpg http://localhost:8080/c.jpg
在實際開發中,可能須要自定義靜態資源訪問路徑,那麼能夠繼承WebMvcConfigurerAdapter來實現。web
package com.sam.demo.conf; import org.springframework.context.annotation.Configuration; import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry; import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter; /** * 配置靜態資源映射 * @author sam * @since 2017/7/16 */ @Configuration public class WebMvcConfig extends WebMvcConfigurerAdapter { @Override public void addResourceHandlers(ResourceHandlerRegistry registry) { //將全部/static/** 訪問都映射到classpath:/static/ 目錄下 registry.addResourceHandler("/static/**").addResourceLocations("classpath:/static/"); } }
spring.mvc.static-path-pattern=/static/**
版權聲明:本文爲博主原創文章,轉載請註明出處。spring