| | |
| | | package com.ruoyi.common.security.config; |
| | | |
| | | import com.fasterxml.jackson.databind.ser.std.ToStringSerializer; |
| | | import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule; |
| | | 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 org.springframework.boot.autoconfigure.jackson.Jackson2ObjectMapperBuilderCustomizer; |
| | | import org.springframework.context.annotation.Bean; |
| | | |
| | | import java.time.LocalDateTime; |
| | | import java.time.format.DateTimeFormatter; |
| | | import java.util.TimeZone; |
| | | |
| | | /** |
| | |
| | | */ |
| | | public class ApplicationConfig |
| | | { |
| | | private static final String DATE_TIME_PATTERN = "yyyy-MM-dd HH:mm:ss"; |
| | | private static final String DATE_PATTERN = "yyyy-MM-dd"; |
| | | /** |
| | | * 时区配置 |
| | | */ |
| | |
| | | builder.serializerByType(Long.class, ToStringSerializer.instance); |
| | | }; |
| | | } |
| | | /** |
| | | * 统一配置 |
| | | */ |
| | | @Bean |
| | | public Jackson2ObjectMapperBuilderCustomizer jsonCustomizer() { |
| | | JavaTimeModule module = new JavaTimeModule(); |
| | | LocalDateTimeDeserializer localDateTimeDeserializer = new LocalDateTimeDeserializer( |
| | | DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")); |
| | | module.addDeserializer(LocalDateTime.class, localDateTimeDeserializer); |
| | | return builder -> { |
| | | builder.simpleDateFormat(DATE_TIME_PATTERN); |
| | | builder.serializers(new LocalDateSerializer(DateTimeFormatter.ofPattern(DATE_PATTERN))); |
| | | builder.serializers(new LocalDateTimeSerializer(DateTimeFormatter.ofPattern(DATE_TIME_PATTERN))); |
| | | builder.modules(module); |
| | | }; |
| | | } |
| | | } |