Administrator
2023-06-19 49588f5a462ae7425e7eb030438a35fd80c246fa
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
package com.gk.firework.Config.Cors;
 
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.WebMvcConfigurer;
 
@Configuration
public class MyMvcConfigurer implements WebMvcConfigurer {
    @Value("${filePath}")
    private String filePath; //配置文件配置的物理保存地址
    @Value("${sqlPath}")
    private String sqlPath;
    @Value("${enterprisePath}")
    private String enterprisePath; //配置文件配置的物理保存地址
    @Value("${contractPath}")
    private String contractPath; //配置文件配置的物理保存地址
    @Value("${transportCertificatePath}")
    private String transportCertificatePath;
    @Value("${hiddenDangerPath}")
    private String hiddenDangerPath;
    @Value("${patrolPath}")
    private String patrolPath;
    @Value("${appPath}")
    private String appPath;
    @Value("${customerPath}")
    private String customerPath;
 
    @Override
    public void addCorsMappings(CorsRegistry registry) {
        registry.addMapping("/**")
                .allowedOrigins("*")
                .allowCredentials(true)
                .allowedMethods("GET", "POST", "DELETE", "PUT","PATCH")
                .maxAge(3600);
    }
 
    /**服务器静态资源配置**/
    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        registry.addResourceHandler("/upload/**")
                .addResourceLocations("file:"+ filePath)   //媒体资源
                .addResourceLocations("classpath:/META-INF/resources/"); //swagger2页面
        registry.addResourceHandler("/dbback/**")
                .addResourceLocations("file:"+sqlPath);
        registry.addResourceHandler("/upload/enterprise/**")
                .addResourceLocations("file:"+enterprisePath);
        registry.addResourceHandler("/upload/contract/**")
                .addResourceLocations("file:"+contractPath);
        registry.addResourceHandler("/upload/transportCertificate/**")
                .addResourceLocations("file:" + transportCertificatePath);
        registry.addResourceHandler("/upload/hiddenDanger/**")
                .addResourceLocations("file:" + hiddenDangerPath);
        registry.addResourceHandler("/upload/patrol/**")
                .addResourceLocations("file:" + patrolPath);
        registry.addResourceHandler("/upload/app/**")
                .addResourceLocations("file:" + appPath);
        registry.addResourceHandler("/upload/customer/**")
                .addResourceLocations("file:" + customerPath);
        registry.addResourceHandler("/logs/**").
                addResourceLocations("file:" + System.getProperty("user.dir") + "/logs/");
 
    }
}