1.默认在src/main/resources目录下新建publi,resources,static,META-INF/resources 通过浏览器可以直接访问
2.在application.properties配置
# 静态文件夹请求匹配方式
spring.mvc.static-path-pattern=/wenjian/**
# 修改默认配置的静态地址资源目录 多个使用逗号分隔
spring.resources.static-locations = classpath:/publi,classpath:/resources,classpath:/static,classpath:/META-INF/resources,classpath:/maytest
配置了路径后,原来的默认方式就会失效,所以我们需要带上
3.通过类的定义来指定静态资源路径
@Configuration
public class MyWebMvcConfigurerAdapter extends WebMvcConfigurerAdapter{
// http:// localhost:8080/mystatic/...jpg
@Override
public void addResourceHandlers(ResourceHandlerRegistry registry){
registry.addResourceHandler("/mystatic/**").addResourceLocations("Classpath:/mystatic");
}
}
注意:本文归作者所有,未经作者允许,不得转载