SpringBoot 时区问题

用springboot写课程设计过程中遇到了这样一个问题,前端收到的内容相差8个小时差,而且格式并不是我们所期待的,去网上找了一下发现了这样一种方案。

//
实体类
package com.bankboot.domain;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.experimental.Accessors;

import java.sql.Timestamp;

@Data
@AllArgsConstructor
@NoArgsConstructor
@Accessors(chain = true)
public class Transact {
    Integer tradId; // 交易ID
    String account;
    String machine;
    Integer tradType;
    Integer balance;
    Timestamp tradingTime;
}
springboot 默认用jackson将对象转json
// application.yml
spring:
  #修改时区配置
  jackson:
    date-format: yyyy-MM-dd HH:mm:ss
    time-zone: GMT+8

修改前

{
    "code": 1,
    "msg": "获取成功",
    "data": [
        {
            "tradId": 10001,
            "account": "10001",
            "machine": "1",
            "tradType": 2,
            "balance": 200,
            "tradingTime": "2022-12-07T02:58:52.737+00:00"
        },
        {
            "tradId": 10002,
            "account": "10001",
            "machine": "1",
            "tradType": 2,
            "balance": 200,
            "tradingTime": "2022-12-07T03:22:50.283+00:00"
        },
        {
            "tradId": 10003,
            "account": "10001",
            "machine": "1",
            "tradType": 2,
            "balance": 200,
            "tradingTime": "2022-12-07T03:24:37.027+00:00"
        }
    ],
    "map": {}
}

修改后

{
    "code": 1,
    "msg": "获取成功",
    "data": [
        {
            "tradId": 10001,
            "account": "10001",
            "machine": "1",
            "tradType": 2,
            "balance": 200,
            "tradingTime": "2022-12-07 10:58:52"
        },
        {
            "tradId": 10002,
            "account": "10001",
            "machine": "1",
            "tradType": 2,
            "balance": 200,
            "tradingTime": "2022-12-07 11:22:50"
        },
        {
            "tradId": 10003,
            "account": "10001",
            "machine": "1",
            "tradType": 2,
            "balance": 200,
            "tradingTime": "2022-12-07 11:24:37"
        }
    ],
    "map": {}
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值