一、springboot 1.x配置
@Configurationpublic
public class MyWebMvcConfigurerAdapter extends WebMvcConfigurerAdapter {
@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) { /**
* 资源映射路径
* addResourceHandler:访问映射路径
* addResourceLocations:资源绝对路径
*/
registry.addResourceHandler("/image/**").addResourceLocations("file:D:/temp/image/");
}
}
记得一定得加上file。file后加上本地磁盘地址文件夹
二、springboot 2.x配置
@Configurationpublic class MyWebAppConfigurer implements WebMvcConfigurer {
@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
registry.addResourceHandler("/image/**").addResourceLocations("file:D:/temp-rainy/");
}
}
然后访问 localhost:8080/image/ 加上图片名。。就可以访问到了。。