目录
LocalDateTime的源码打印中是默认在日期和时间点中间加了个T的
LocalDateTime源码:
@Overridepublic String toString() {return date.toString() + 'T' + time.toString();}
1.在实体类中加注解
在实体类中加入下列代码,我是这样处理的(我是在往前台传展示的时候发现的这个问题)
@JsonFormat(timezone = "GMT+8",pattern = "yyyy-MM-dd HH:mm:ss")
2.直接转换
当前时间.replace(/T/g, ' ').replace(/.[\d]{3}Z/, ' ') 即可去掉T ;
3.参考网上其他博客
@Configurationpublic class LocalDateTimeSerializerConfig { @org.springframework.beans.factory.annotation.Value("${spring.jackson.date-format:yyyy-MM-dd HH:mm:ss}") private String pattern; @Bean public LocalDateTimeSerializer localDateTimeDeserializer() { return new LocalDateTimeSerializer(DateTimeFormatter.ofPattern(pattern)); } @Bean public Jackson2ObjectMapperBuilderCustomizer jackson2ObjectMapperBuilderCustomizer() { return builder -> builder.serializerByType(LocalDateTime.class, localDateTimeDeserializer()); }}
来源地址:https://blog.csdn.net/m0_61983575/article/details/129765809