作者 RuoYi

Jackson日期反序列化时区问题

1 package com.ruoyi.framework.config; 1 package com.ruoyi.framework.config;
2 2
  3 +import java.util.TimeZone;
3 import org.mybatis.spring.annotation.MapperScan; 4 import org.mybatis.spring.annotation.MapperScan;
  5 +import org.springframework.boot.autoconfigure.jackson.Jackson2ObjectMapperBuilderCustomizer;
  6 +import org.springframework.context.annotation.Bean;
4 import org.springframework.context.annotation.Configuration; 7 import org.springframework.context.annotation.Configuration;
5 import org.springframework.context.annotation.EnableAspectJAutoProxy; 8 import org.springframework.context.annotation.EnableAspectJAutoProxy;
6 9
@@ -16,5 +19,12 @@ import org.springframework.context.annotation.EnableAspectJAutoProxy; @@ -16,5 +19,12 @@ import org.springframework.context.annotation.EnableAspectJAutoProxy;
16 @MapperScan("com.ruoyi.project.**.mapper") 19 @MapperScan("com.ruoyi.project.**.mapper")
17 public class ApplicationConfig 20 public class ApplicationConfig
18 { 21 {
19 - 22 + /**
  23 + * 时区配置
  24 + */
  25 + @Bean
  26 + public Jackson2ObjectMapperBuilderCustomizer jacksonObjectMapperCustomization()
  27 + {
  28 + return jacksonObjectMapperBuilder -> jacksonObjectMapperBuilder.timeZone(TimeZone.getDefault());
  29 + }
20 } 30 }