在接收JSON格式的RequestBody,返回JSON格式数据的接口中,有三个地方涉及到时间格式化:
1.参数
2.RequestBody
3.返回结果
@DateTimeFormat的作用域是参数
@JsonFormat的作用域是RequestBody和返回结果
对于参数而言,org.springframework.core.convert.converter.Converter<S, T>的优先级高于@DateTimeFormat,也就是定义了对应时间类型的转换器,@DateTimeFormat不再起作用,格式化以转换器为准;
对于RequestBody和返回结果,@JsonFormat的优先级高于org.springframework.http.converter.HttpMessageConverter<T>,在定义了MappingJackson2HttpMessageConverter对时间的序列化与反序列化的情况下,如果Field注解了@JsonFormat且格式不一致,以@JsonFormat注解格式为准