美文网首页
配置本地文件上传路径,达到文件服务器的效果

配置本地文件上传路径,达到文件服务器的效果

作者: 枯萎天然呆 | 来源:发表于2023-10-18 16:40 被阅读0次
    package com.ruoyi.framework.config;
    
    import java.util.concurrent.TimeUnit;
    import org.springframework.beans.factory.annotation.Autowired;
    import org.springframework.context.annotation.Bean;
    import org.springframework.context.annotation.Configuration;
    import org.springframework.http.CacheControl;
    import org.springframework.web.cors.CorsConfiguration;
    import org.springframework.web.cors.UrlBasedCorsConfigurationSource;
    import org.springframework.web.filter.CorsFilter;
    import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
    import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
    import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
    
    
    /**
     * 通用配置
     * 
     * @author ruoyi
     */
    @Configuration
    public class ResourcesConfig implements WebMvcConfigurer
    {
        @Autowired
        private RepeatSubmitInterceptor repeatSubmitInterceptor;
    
        @Override
        public void addResourceHandlers(ResourceHandlerRegistry registry)
        {
            /*        Constants.RESOURCE_PREFIX + "/**":这个路径模式表示所有以/resource/开头的请求都会被映射到本地文件系统。
             addResourceLocations("file:" + RuoYiConfig.getProfile() + "/"):指定了这些静态资源在本地文件系统中的位置。RuoYiConfig.getProfile()获取了配置中的文件上传路径。
             举例来说,如果Constants.RESOURCE_PREFIX是/resource,而RuoYiConfig.getProfile()返回的是/uploads,那么访问/resource/image.jpg将会映射到本地文件系统的/uploads/image.jpg。*/
            /** 本地文件上传路径 */
            //public static final String RESOURCE_PREFIX = "/resource";
            registry.addResourceHandler(Constants.RESOURCE_PREFIX + "/**")
                    .addResourceLocations("file:" + RuoYiConfig.getProfile() + "/");
    
        }
    
      
    }
    

    相关文章

      网友评论

          本文标题:配置本地文件上传路径,达到文件服务器的效果

          本文链接:https://www.haomeiwen.com/subject/bvjcidtx.html