若依微服务,登录日志和操作日志,发现日期时间比数据库时间少8个小时

若依微服务,登录日志和操作日志,发现日期时间比数据库时间少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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值