【Springboot】 Spirngboot2-Vue3注解式方法解决数据前台时间显示为“2023-10-31T10:00:00.000+00:00”格式问题

项目场景:

项目版本:
后端: Springboot 2.7、 Mybatis-plus、Maven 3.8.1
数据库:MySQL 8.0
前端:Vue3、Axois 1.6.0 、Vite 4.5.0、Element-Plus、Router-v4


问题描述

前端日期格式显示并不是我们想要的格式:
在这里插入图片描述

数据库关于日期字段check_incheck_out都是date类型,在表格中的数据格式如图:
在这里插入图片描述
后端对应的实体类设计:

@Data
@TableName(value = "tborders")
public class Orders {
    
    
    private String orderId;
    private String clientName;
    private String clientSex;
    private String clientCard;
    private String clientPhone;
    
    private Date checkIn;
    private Date checkOut;
    private String roomType;
}

解决方案

实体类上添加注解:

@Data
@TableName(value = "tborders")
public class Orders {
    
    
    private String orderId;
    private String clientName;
    private String clientSex;
    private String clientCard;
    private String clientPhone;
    @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    private Timestamp checkIn;
    @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    private Timestamp checkOut;
    private String roomType;

}

问题解决:
在这里插入图片描述

猜你喜欢

转载自blog.csdn.net/SKMIT/article/details/134314920