zhangfeng
2023-07-27 cc3ddfda6bfb9a2aa0cd55073e8864320daf1f20
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
package com.gk.hotwork.Config.Cors;
 
import com.gk.hotwork.Config.attachment.FilePathConfig;
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("${workCertPath}")
    private String workCertPath;
    @Value("${taskPath}")
    private String taskPath;
    @Value("${emergencyPlanPath}")
    private String emergencyPlanPath;
 
    @Value("${file.path.dcPath}")
    private String dcPath;
 
    @Value("${file.path.urlRootPath}")
    private String urlRootPath;
 
 
    @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/workCert/**")
                .addResourceLocations("file:" + workCertPath);
        registry.addResourceHandler("/upload/task/**")
                .addResourceLocations("file:" + taskPath);
        registry.addResourceHandler("/upload/emergencyPlan/**")
                .addResourceLocations("file:" + emergencyPlanPath);
        registry.addResourceHandler("/uploadfile/**")
                .addResourceLocations("file:" + dcPath);
    }
}