From ca5445257b1fdeceddf3fcc2dea18c442023aeb7 Mon Sep 17 00:00:00 2001
From: kongzy <kongzy>
Date: 星期五, 08 十二月 2023 09:30:36 +0800
Subject: [PATCH] 新街口

---
 assess-framework/src/main/java/com/gkhy/assess/framework/config/ApplicationConfig.java |   29 ++++++++++++++++++++++++++---
 1 files changed, 26 insertions(+), 3 deletions(-)

diff --git a/assess-framework/src/main/java/com/gkhy/assess/framework/config/ApplicationConfig.java b/assess-framework/src/main/java/com/gkhy/assess/framework/config/ApplicationConfig.java
index 88c51df..579768a 100644
--- a/assess-framework/src/main/java/com/gkhy/assess/framework/config/ApplicationConfig.java
+++ b/assess-framework/src/main/java/com/gkhy/assess/framework/config/ApplicationConfig.java
@@ -1,6 +1,9 @@
 package com.gkhy.assess.framework.config;
 
+import com.fasterxml.jackson.datatype.jsr310.deser.LocalDateTimeDeserializer;
+import com.fasterxml.jackson.datatype.jsr310.ser.LocalDateTimeSerializer;
 import org.mybatis.spring.annotation.MapperScan;
+import org.springframework.beans.factory.annotation.Value;
 import org.springframework.boot.autoconfigure.jackson.Jackson2ObjectMapperBuilderCustomizer;
 import org.springframework.context.annotation.Bean;
 import org.springframework.context.annotation.Conditional;
@@ -10,6 +13,8 @@
 import org.springframework.web.cors.UrlBasedCorsConfigurationSource;
 import org.springframework.web.filter.CorsFilter;
 
+import java.time.LocalDateTime;
+import java.time.format.DateTimeFormatter;
 import java.util.TimeZone;
 
 /**
@@ -24,15 +29,33 @@
 @MapperScan("com.gkhy.**.mapper")
 public class ApplicationConfig
 {
+
+    @Value("${spring.jackson.date-format:yyyy-MM-dd HH:mm:ss}")
+    private String pattern;
+
     /**
      * 时区配置
      */
+//    @Bean
+//    public Jackson2ObjectMapperBuilderCustomizer jacksonObjectMapperCustomization()
+//    {
+//        return jacksonObjectMapperBuilder -> jacksonObjectMapperBuilder.timeZone(TimeZone.getDefault());
+//    }
+
     @Bean
-    public Jackson2ObjectMapperBuilderCustomizer jacksonObjectMapperCustomization()
-    {
-        return jacksonObjectMapperBuilder -> jacksonObjectMapperBuilder.timeZone(TimeZone.getDefault());
+    public Jackson2ObjectMapperBuilderCustomizer jackson2ObjectMapperBuilderCustomizer() {
+        return builder -> {
+            DateTimeFormatter formatter = DateTimeFormatter.ofPattern(pattern);
+
+            //返回时间数据序列化
+            builder.serializerByType(LocalDateTime.class, new LocalDateTimeSerializer(formatter));
+            //接收时间数据反序列化
+            builder.deserializerByType(LocalDateTime.class, new LocalDateTimeDeserializer(formatter));
+            builder.timeZone(TimeZone.getDefault());
+        };
     }
 
+
     @Bean
     public CorsFilter corsFilter() {
         final UrlBasedCorsConfigurationSource urlBasedCorsConfigurationSource = new UrlBasedCorsConfigurationSource();

--
Gitblit v1.9.2