Spring Boot后端与Angular前端进行timestamp的交互

后端使用java.sql.Timestamp

后端vo字段类型使用

import java.sql.Timestamp;

Mapper可以为字段加上属性jdbcType="TIMESTAMP" 也可以不加

<result property="startTime" column="start_time" jdbcType="TIMESTAMP"/>

Angular前端vo

无论后端使用什么类型进行时间戳转换,都需要前端将Date转换成时间戳的形式(number)

java.sql.Timestamp
java.sql.Date
java.util.Date

前端字段

startTime: number;

vo赋值时使用

this.testVo.startTime = Date.parse(new Date().toString())

从后端获取数据后需要在前端进行转换

new Date(this.testVo.startTime)

个人博客 蜗牛

原文地址:https://www.cnblogs.com/codeobj/p/11856622.html