SpringBoot配置虚拟映射路径

方法一:

1、需要先在application.properties属性文件中配置本地上传文件的路径:

prop.upload-folder=E:

2、将本地上传文件的路径加入到静态资源路径中即可:

spring.resources.static-locations=classpath:/META-INF/resources/,classpath:/resources/,\
  classpath:/static/,classpath:/public/,file:${prop.upload-folder}

方法二:

import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;

@Configuration
public class SpringbootIntercepterConfig extends WebMvcConfigurerAdapter {

    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry){

        registry.addResourceHandler("/**").addResourceLocations("file:E://");
         super.addResourceHandlers(registry);
    }

}

3.地址栏中访问

http://localhost:8080/images/Koala.jpg

你可能感兴趣的:(SpringBoot)