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")) { |
| registry.addResourceHandler("/虚拟路径目录名称/**"). |
| addResourceLocations("file:盘符名称:\\文件绝对路径(真实物理路径)/"); |
| }else{ |
| registry.addResourceHandler("/productPic/**"). |
| addResourceLocations("file:/uploadBaseDir/productPic/"); |
| } |
| super.addResourceHandlers(registry); |
| |
| } |
| } |