hr~ 3 недель назад
Родитель
Сommit
96412fcaa6
1 измененных файлов с 17 добавлено и 0 удалено
  1. 17 0
      py-starter/src/main/java/com/poyee/PoyeeDashboardApplication.java

+ 17 - 0
py-starter/src/main/java/com/poyee/PoyeeDashboardApplication.java

@@ -4,13 +4,17 @@ import lombok.extern.slf4j.Slf4j;
 
 import org.springframework.boot.SpringApplication;
 import org.springframework.boot.autoconfigure.SpringBootApplication;
+import org.springframework.boot.autoconfigure.jackson.Jackson2ObjectMapperBuilderCustomizer;
 import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
 import org.springframework.boot.autoconfigure.security.servlet.SecurityAutoConfiguration;
+import org.springframework.context.annotation.Bean;
 import org.springframework.context.annotation.EnableAspectJAutoProxy;
 import org.springframework.scheduling.annotation.EnableAsync;
 import org.springframework.scheduling.annotation.EnableScheduling;
 import org.springframework.transaction.annotation.EnableTransactionManagement;
 
+import java.util.TimeZone;
+
 /**
  * 项目启动
  */
@@ -22,10 +26,23 @@ import org.springframework.transaction.annotation.EnableTransactionManagement;
 @EnableScheduling
 @Slf4j
 public class PoyeeDashboardApplication {
+    private static final String APPLICATION_TIME_ZONE = "Asia/Shanghai";
 
     public static void main(String[] args) {
+        configureApplicationTimeZone();
         SpringApplication.run(PoyeeDashboardApplication.class, args);
         log.info("(♥◠‿◠)ノ゙ 启动成功   ლ(´ڡ`ლ)゙");
     }
 
+    static void configureApplicationTimeZone() {
+        TimeZone.setDefault(TimeZone.getTimeZone(APPLICATION_TIME_ZONE));
+    }
+
+    @Bean
+    public Jackson2ObjectMapperBuilderCustomizer jacksonObjectMapperCustomization() {
+        return jacksonObjectMapperBuilder -> jacksonObjectMapperBuilder
+                .timeZone(TimeZone.getTimeZone(APPLICATION_TIME_ZONE))
+                .simpleDateFormat("yyyy-MM-dd HH:mm:ss");
+    }
+
 }