1.首先在Application同级目录创建一个class:WebConfig
2.WebConfig继承WebMvcConfigureerAdapter,并重写addResourceHandlers方法;
3.添加配置:registry.addResourceHandler("/**").addResourceLocations("file:/Users/hou/Documents/imooc_upload/");
代码:
public class WebMvcConfig extends WebMvcConfigurerAdapter {
@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
registry.addResourceHandler("/**").addResourceLocations("file:/Users/hou/Documents/imooc_upload/");
}
}
网友评论