content: package com.achobeta.config;
  
  import com.fasterxml.jackson.datatype.jsr310.deser.LocalDateDeserializer;
  import com.fasterxml.jackson.datatype.jsr310.deser.LocalDateTimeDeserializer;
  import com.fasterxml.jackson.datatype.jsr310.ser.LocalDateSerializer;
  import com.fasterxml.jackson.datatype.jsr310.ser.LocalDateTimeSerializer;
  import com.fasterxml.jackson.module.paramnames.ParameterNamesModule;
  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.EnableWebMvc;
  import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
  
  import java.text.DateFormat;
  import java.text.SimpleDateFormat;
  import java.time.format.DateTimeFormatter;
  import java.util.List;
  
  
  @Configuration
  @EnableWebMvc
  public class DateTimeConfig implements WebMvcConfigurer {
  
      /**
       * 定义全局默认时间序列化
       */
      public static final String DATE_TIME_PATTERN = "yyyy-MM-dd HH:mm:ss";
  
      public static final String DATE_PATTERN = "yyyy-MM-dd";
  
      public static final DateFormat DATE_TIME_FORMAT = new SimpleDateFormat(DATE_TIME_PATTERN);
  
      public static final DateFormat DATE_FORMAT = new SimpleDateFormat(DATE_PATTERN);
  
      @Override
      public void configureMessageConverters(List<HttpMessageConverter<?>> converters) {
          Jackson2ObjectMapperBuilder builder = new Jackson2ObjectMapperBuilder()
                  .indentOutput(Boolean.TRUE)
                  .dateFormat(DATE_FORMAT)
                  .simpleDateFormat(DATE_TIME_PATTERN)
                  .serializers(new LocalDateTimeSerializer(DateTimeFormatter.ofPattern(DATE_TIME_PATTERN)))
                  .serializers(new LocalDateSerializer(DateTimeFormatter.ofPattern(DATE_PATTERN)))
                  .deserializers(new LocalDateTimeDeserializer(DateTimeFormatter.ofPattern(DATE_TIME_PATTERN)))
                  .deserializers(new LocalDateDeserializer(DateTimeFormatter.ofPattern(DATE_PATTERN)))
                  .modulesToInstall(new ParameterNamesModule());
          converters.add(new MappingJackson2HttpMessageConverter(builder.build()));
      }
  }
  
  