首页 > 文章列表 > springboot中如何实现默认静态路径

springboot中如何实现默认静态路径

springboot
288 2023-05-19

springboot中如何实现默认静态路径

类ResourceProperties.class

private static final String[] CLASSPATH_RESOURCE_LOCATIONS = new String[]{"classpath:/META-INF/resources/", "classpath:/resources/", "classpath:/static/", "classpath:/public/"};

private String[] staticLocations;



public ResourceProperties() {

 this.staticLocations = CLASSPATH_RESOURCE_LOCATIONS;

 this.addMappings = true;

 this.chain = new ResourceProperties.Chain();

 this.cache = new ResourceProperties.Cache();

}

根据构造方法可知, staticLocations等于默认的CLASSPATH_RESOURCE_LOCATIONS, 也即"classpath:/META-INF/resources/", "classpath:/resources/", "classpath:/static/", "classpath:/public/"

classpath即为我们如下图所示的resource文件夹