feat(WebMvcConfig): 优化 JSON 序列化中的日期格式
- 在 ObjectMapper 中设置日期格式为 "yyyy-MM-dd HH:mm:ss" - 优化配置消息转换器导致配置文件中的date-format: yyyy-MM-dd HH:mm:ss失效
This commit is contained in:
@@ -20,6 +20,7 @@ import org.springframework.validation.beanvalidation.SpringConstraintValidatorFa
|
|||||||
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
|
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
|
||||||
|
|
||||||
import java.math.BigInteger;
|
import java.math.BigInteger;
|
||||||
|
import java.text.SimpleDateFormat;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -50,6 +51,7 @@ public class WebMvcConfig implements WebMvcConfigurer {
|
|||||||
simpleModule.addSerializer(Long.class, ToStringSerializer.instance);
|
simpleModule.addSerializer(Long.class, ToStringSerializer.instance);
|
||||||
simpleModule.addSerializer(BigInteger.class, ToStringSerializer.instance);
|
simpleModule.addSerializer(BigInteger.class, ToStringSerializer.instance);
|
||||||
objectMapper.registerModule(simpleModule);
|
objectMapper.registerModule(simpleModule);
|
||||||
|
objectMapper.setDateFormat(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"));
|
||||||
|
|
||||||
jackson2HttpMessageConverter.setObjectMapper(objectMapper);
|
jackson2HttpMessageConverter.setObjectMapper(objectMapper);
|
||||||
converters.add(1, jackson2HttpMessageConverter);
|
converters.add(1, jackson2HttpMessageConverter);
|
||||||
|
|||||||
Reference in New Issue
Block a user