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/"); 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> converters) { converters.removeIf(c -> c instanceof MappingJackson2HttpMessageConverter); converters.add(new MappingJackson2HttpMessageConverter(jacksonObjectMapperCustomization())); } }