Feature 添加JacksonConfig配置对日期格式化

This commit is contained in:
guosongrui
2024-05-13 19:14:19 +08:00
parent f39b45a438
commit cc24fc3124
3 changed files with 26 additions and 1 deletions

View File

@@ -52,7 +52,7 @@
<!--服务器发布内容为空-->
<!-- <nacos.namespace></nacos.namespace>-->
<!-- <nacos.namespace>1dd11af6-e668-41fd-a663-02a05705304d</nacos.namespace>-->
<nacos.namespace>fd74182b-1fce-4dba-afa7-2623b0376205</nacos.namespace>
<nacos.namespace>6d75b5c3-cff9-4c4a-8e8b-ca2363753ecb</nacos.namespace>
<!-- sentinel:port-->
<sentinel.url>${middle.server.url}:8080</sentinel.url>
<!--网关地址主要用于配置swagger中认证token-->

View File

@@ -0,0 +1,22 @@
package com.njcn.bpm.config;
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
import com.fasterxml.jackson.datatype.jsr310.ser.LocalDateTimeSerializer;
import org.springframework.boot.autoconfigure.jackson.Jackson2ObjectMapperBuilderCustomizer;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
@Configuration
public class JacksonConfig {
public static final String DATE_TIME_FORMAT = "yyyy-MM-dd HH:mm:ss";
@Bean
public Jackson2ObjectMapperBuilderCustomizer jsonCustomizer() {
return builder -> { builder.simpleDateFormat(DATE_TIME_FORMAT);
JavaTimeModule module = new JavaTimeModule(); module.addSerializer(LocalDateTime.class, new LocalDateTimeSerializer(DateTimeFormatter.ofPattern(DATE_TIME_FORMAT)));
builder.modules(module);
};
}
}

View File

@@ -16,6 +16,9 @@ feign:
spring:
application:
name: @artifactId@
jackson:
date-format: yyyy-MM-dd HH:mm:ss
time-zone: Asia/Shanghai
#nacos注册中心以及配置中心的指定
cloud:
nacos: