Springboot配置虚拟路径(Linux和Windows),映射本地磁盘文件!!!(1秒搞定)

Springboot配置虚拟路径,映射本地磁盘文件!!!(1秒搞定)

封装工具类即可


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 WebMvcConfigurer extends WebMvcConfigurerAdapter {
 
    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
    //Linux
        registry.addResourceHandler("/wenjianming/**").addResourceLocations("file:/home/wenjianming/");
    //Windows
        registry.addResourceHandler("/wenjianming/**").addResourceLocations("file:C:\\wenjianming\\");
    }
}

访问方式 http://localhost:80/wenjianming/文件名.png

你可能感兴趣的:(springboot,虚拟路径,Springboot,java,映射本地磁盘文件)