SpringBoot配置静态资源访问与本地路径的映射

Posted JAVA ROAD

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了SpringBoot配置静态资源访问与本地路径的映射相关的知识,希望对你有一定的参考价值。

1、配置工程访问路径映射本地路径;

package com.liuyanzhao.chuyun.config;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
/**
 * @author yhq
 * @date 2018/2/27 下午3:32
 */
@Configuration
public class ApplicationConfig extends WebMvcConfigurerAdapter {
    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
       
        //Windows下
        registry.addResourceHandler("/uploads2/**").addResourceLocations("file:D:/uploads2/");
        //Mac或Linux下(没有CDEF盘符)
        registry.addResourceHandler("/uploads/**").addResourceLocations("file:/Users/uploads/");
        super.addResourceHandlers(registry);
    }
}

 

以上是关于SpringBoot配置静态资源访问与本地路径的映射的主要内容,如果未能解决你的问题,请参考以下文章