项目场景:
项目版本:
后端: 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_in
和check_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;
}
问题解决: