package com.example;

import com.example.util.uploadLocalost.FileConstants;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;

/**
 * 〈一句话功能简述〉<br>
 * 〈配置拦截跨域〉
 *
 * @author xunyong
 * @create 2018/12/28
 * @since 1.0.0
 */
@Configuration
public class MyWebAppConfigurer extends WebMvcConfigurerAdapter {

    @Override
    public void addCorsMappings(CorsRegistry registry) {
        registry.addMapping("/**");
    }

    @Value("${file.path}")
    private String filePath = "D:/";

    /**
     * 静态资源映射，使Java可以访问E文件下下面的东西，映射路径为/core/**
     *
     * @param registry
     */
    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        registry.addResourceHandler("/"+ FileConstants.FILE_URL_NAME+"/**").addResourceLocations("file:" + filePath + FileConstants.FILE_URL_NAME+"/");
    }
}