若依微服务,登录日志和操作日志,发现日期时间比数据库时间少8个小时
通过分析,数据库时间正常
controller ——》list的时间正常
postMan调用,返回的json日期少了8个小时
修改Jackson配置:
public MappingJackson2HttpMessageConverter jackson2HttpMessageConverter() {
final Jackson2ObjectMapperBuilder builder = new Jackson2ObjectMapperBuilder();
builder.serializationInclusion(JsonInclude.Include.NON_NULL)
.timeZone(TimeZone.getTimeZone("GMT+8")); // 设置全局时区为GMT+8
final ObjectMapper objectMapper = builder.build();
SimpleModule simpleModule = new SimpleModule();
// Long 转为 String 防止 js 丢失精度
simpleModule.addSerializer(Long.class, ToStringSerializer.instance);
objectMapper.registerModule(simpleModule);
// 忽略 transient 关键词属性
objectMapper.configure(MapperFeature.PROPAGATE_TRANSIENT_MARKER, true);
return new MappingJackson2HttpMessageConverter(objectMapper);
通过设置全局设置全局时区为GMT+8解决
主要添加:
builder.serializationInclusion(JsonInclude.Include.NON_NULL)
.timeZone(TimeZone.getTimeZone(“GMT+8”)); // 设置全局时区为GMT+8

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



