一、出参处理
springBoot项目中使用注解@ResponseBody或者@RestController默认使用Json格式返回数据。
默认返回的格式是这样的"2021-04-28T07:01:45.000+00:00",如下
我们可能想要返回给前端是yyyy-MM-dd HH:mm:ss 这样的格式
全局配置
若此配置无效,返回的时间还是上面那种中间带‘T’的那种格式的话,
解决方案
实现WebMvcConfigurer的extendMessageConverters方法
@Configuration
public class DateTimeSerializerConfig implements WebMvcConfigurer {
@Value("${spring.jackson.date-format}")
private String pattern;
/**
* 时间出参序列化
* 使用此方法, 以下 spring-boot: jackson时间格式化 配置 将会失效
* spring.jackson.date-format=yyyy-MM-dd H