其他分享
首页 > 其他分享> > SpringMVC中资源路径映射本地文件图片

SpringMVC中资源路径映射本地文件图片

作者:互联网

SpringMVC中资源路径映射本地文件图片

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 ResourceConfigAdapter extends WebMvcConfigurerAdapter {
    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        String os = System.getProperty("os.name");
        if (os.toLowerCase().startsWith("win")) {  //如果是Windows系统
            registry.addResourceHandler("/虚拟路径目录名称/**").
                    addResourceLocations("file:盘符名称:\\文件绝对路径(真实物理路径)/");
        }else{//linux和mac系统
            registry.addResourceHandler("/productPic/**").
                    addResourceLocations("file:/uploadBaseDir/productPic/");
        }
        super.addResourceHandlers(registry);

    }
}

标签:映射,SpringMVC,路径,springframework,registry,org,import,os,annotation
来源: https://www.cnblogs.com/guobabiancheng/p/16410778.html