|
|
@@ -20,6 +20,8 @@ import org.springframework.context.annotation.Bean;
|
|
|
import org.springframework.context.annotation.Conditional;
|
|
|
import org.springframework.context.annotation.Configuration;
|
|
|
import org.springframework.context.annotation.Primary;
|
|
|
+import org.springframework.format.FormatterRegistry;
|
|
|
+import org.springframework.format.datetime.DateFormatterRegistrar;
|
|
|
import org.springframework.http.converter.HttpMessageConverter;
|
|
|
import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter;
|
|
|
import org.springframework.web.cors.CorsConfiguration;
|
|
|
@@ -34,8 +36,10 @@ import java.text.SimpleDateFormat;
|
|
|
import java.time.LocalDate;
|
|
|
import java.time.LocalDateTime;
|
|
|
import java.time.LocalTime;
|
|
|
+import java.time.ZoneId;
|
|
|
import java.time.format.DateTimeFormatter;
|
|
|
import java.util.List;
|
|
|
+import java.util.TimeZone;
|
|
|
|
|
|
/**
|
|
|
* Spring Boot 2.0 解决跨域问题
|
|
|
@@ -54,6 +58,15 @@ public class WebMvcConfiguration implements WebMvcConfigurer {
|
|
|
@Autowired(required = false)
|
|
|
private PrometheusMeterRegistry prometheusMeterRegistry;
|
|
|
|
|
|
+ @Override
|
|
|
+ public void addFormatters(FormatterRegistry registry) {
|
|
|
+ DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'")
|
|
|
+ .withZone(ZoneId.of("UTC"));
|
|
|
+ DateFormatterRegistrar registrar = new DateFormatterRegistrar();
|
|
|
+ registrar.setFormatter(new DateTimeFormatterAdapter(formatter));
|
|
|
+ registrar.registerFormatters(registry);
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 静态资源的配置 - 使得可以从磁盘中读取 Html、图片、视频、音频等
|
|
|
*/
|
|
|
@@ -114,15 +127,16 @@ public class WebMvcConfiguration implements WebMvcConfigurer {
|
|
|
objectMapper.configure(DeserializationFeature.FAIL_ON_NULL_FOR_PRIMITIVES, false);
|
|
|
objectMapper.configure(DeserializationFeature.FAIL_ON_NULL_CREATOR_PROPERTIES, false);
|
|
|
//默认的处理日期时间格式
|
|
|
- objectMapper.setDateFormat(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"));
|
|
|
- JavaTimeModule javaTimeModule = new JavaTimeModule();
|
|
|
- javaTimeModule.addSerializer(LocalDateTime.class, new LocalDateTimeSerializer(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")));
|
|
|
- javaTimeModule.addSerializer(LocalDate.class, new LocalDateSerializer(DateTimeFormatter.ofPattern("yyyy-MM-dd")));
|
|
|
- javaTimeModule.addSerializer(LocalTime.class, new LocalTimeSerializer(DateTimeFormatter.ofPattern("HH:mm:ss")));
|
|
|
- javaTimeModule.addDeserializer(LocalDateTime.class, new LocalDateTimeDeserializer(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")));
|
|
|
- javaTimeModule.addDeserializer(LocalDate.class, new LocalDateDeserializer(DateTimeFormatter.ofPattern("yyyy-MM-dd")));
|
|
|
- javaTimeModule.addDeserializer(LocalTime.class, new LocalTimeDeserializer(DateTimeFormatter.ofPattern("HH:mm:ss")));
|
|
|
- objectMapper.registerModule(javaTimeModule);
|
|
|
+ objectMapper.setTimeZone(TimeZone.getTimeZone("UTC"));
|
|
|
+ objectMapper.setDateFormat(new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'"));
|
|
|
+// JavaTimeModule javaTimeModule = new JavaTimeModule();
|
|
|
+// javaTimeModule.addSerializer(LocalDateTime.class, new LocalDateTimeSerializer(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")));
|
|
|
+// javaTimeModule.addSerializer(LocalDate.class, new LocalDateSerializer(DateTimeFormatter.ofPattern("yyyy-MM-dd")));
|
|
|
+// javaTimeModule.addSerializer(LocalTime.class, new LocalTimeSerializer(DateTimeFormatter.ofPattern("HH:mm:ss")));
|
|
|
+// javaTimeModule.addDeserializer(LocalDateTime.class, new LocalDateTimeDeserializer(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")));
|
|
|
+// javaTimeModule.addDeserializer(LocalDate.class, new LocalDateDeserializer(DateTimeFormatter.ofPattern("yyyy-MM-dd")));
|
|
|
+// javaTimeModule.addDeserializer(LocalTime.class, new LocalTimeDeserializer(DateTimeFormatter.ofPattern("HH:mm:ss")));
|
|
|
+// objectMapper.registerModule(javaTimeModule);
|
|
|
return objectMapper;
|
|
|
}
|
|
|
|