package com.common.config;
import org.springframework.boot.autoconfigure.jackson.Jackson2ObjectMapperBuilderCustomizer;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
@Configuration
public class JsonConfig {
@Bean
public Jackson2ObjectMapperBuilderCustomizer jsonCustomizer() {
return builder -> {
builder.simpleDateFormat("yyyy-MM-dd HH:mm:ss");
};
}
}
【替代】实体类日期格式化:
/** 创建时间 */
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
private Date createTime;
本文介绍如何使用Spring Boot自定义项目中JSON日期的格式化方式,通过配置类实现全局日期格式统一为yyyy-MM-dd HH:mm:ss,并提供实体类字段格式化的替代方案。
1267

被折叠的 条评论
为什么被折叠?



