whycxzp
2025-04-02 74b253223abe7cd821ca5071a2bdcea7cd4f5352
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
package com.whyc.config;
 
import com.fasterxml.jackson.databind.ObjectMapper;
import org.springframework.boot.system.ApplicationHome;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.converter.HttpMessageConverter;
import org.springframework.http.converter.json.Jackson2ObjectMapperBuilder;
import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter;
import org.springframework.web.servlet.config.annotation.*;
 
import java.io.File;
import java.text.SimpleDateFormat;
import java.util.List;
import java.util.TimeZone;
 
/**
 * @Description : static resources Config
 * @date 2020/09/15
 **/
@Configuration
@EnableWebMvc
public class StaticResourceConfig extends WebMvcConfigurerAdapter {
 
    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
 
        //这个是可行的,解析的时候path为*.html,校验路径admin下是否存在
        registry.addResourceHandler("/**").addResourceLocations("classpath:/META-INF/resources/");
        //录像视频mp4文件路径转为http url
        registry.addResourceHandler("/video/**").addResourceLocations("file:/battery_system/video_system/ZLMediaKit/www/record/rtp/");
        //巡检记录文件和视频
        registry.addResourceHandler("/inspectRecord/video/**").addResourceLocations("file:/mnt/disk2/YunNan3/video/");
        registry.addResourceHandler("/inspectRecord/recordAnalysis/**").addResourceLocations("file:/mnt/disk2/YunNan3/reportAnalysis/");
        //registry.addResourceHandler("/inspectRecord/video/**").addResourceLocations("file:\\C:\\Users\\29550\\Desktop\\当前项目\\2023\\0智能机器人运维系统\\巡检记录\\video\\");
        //registry.addResourceHandler("/inspectRecord/recordAnalysis/**").addResourceLocations("file:\\C:\\Users\\29550\\Desktop\\当前项目\\2023\\0智能机器人运维系统\\巡检记录\\recordAnalysis\\");
        super.addResourceHandlers(registry);
 
    }
 
    @Bean
    public ObjectMapper jacksonObjectMapperCustomization() {
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        TimeZone timeZone = TimeZone.getTimeZone("Asia/Shanghai");
        format.setTimeZone(timeZone);
 
        Jackson2ObjectMapperBuilder builder = new Jackson2ObjectMapperBuilder()
                .timeZone(timeZone)
                .dateFormat(format);
 
        return builder.build();
    }
 
    @Override
    public void configureMessageConverters(List<HttpMessageConverter<?>> converters) {
        converters.removeIf(c -> c instanceof MappingJackson2HttpMessageConverter);
        converters.add(new MappingJackson2HttpMessageConverter(jacksonObjectMapperCustomization()));
    }
 
}