Springboot添加静态资源映射addResourceHandlers,可实现url访问

@Configuration
//public class WebMvcConfiger extends WebMvcConfigurerAdapter {
public class WebMvcConfiger implements WebMvcConfigurer {
    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        registry.addResourceHandler("/picture/**").addResourceLocations("file:D:/picture/");
    }
}
registry.addResourceHandler("/picture/**")  
//表示文件路径,这里的意思是picture包下的所有文件,所有/picture/开头的请求 都会去后面配置的路径下查找资源
.addResourceLocations("file:D:/picture/"); 
//表示要开放的资源

 

 
posted @ 2020-11-04 14:40  生活这把杀猪刀  阅读(10192)  评论(0编辑  收藏  举报