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);
- }
- }
复制代码 免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作! |