Fork me on GitHub

mybatis中的datetime与java中的Date类型映射问题

疑惑:

使用mybatis 从数据库中查询出date 类型字段,在java 类型中只看到了日期,没有看到时分秒,从数据库中是可以看到时分秒的。

解惑:

<result column="CREATEDATE" property="createdate" jdbcType="Date" />

 映射出来的时间格式时分秒都为0 (2020-12-04 00:00:00)

<result column="PICKUPDATE" property="pickupdate" jdbcType="TIMESTAMP" />

 映射出来的时间格式有时分秒 (2020-12-04 11:05:11)

补充知识:springboot 返回Date类型数据 格式化

1.提示类的get方法上增加JsonFormat

@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss",timezone = "GMT+8")
 public Date getCreateTime() {
  return createTime;
 }

2.或者在配置文件中增加

spring:
  jackson:
 date-format: yyyy-MM-dd HH:mm:ss
 time-zone: GMT+8

 

posted @ 2020-12-04 11:26  w_wz  阅读(4308)  评论(0编辑  收藏  举报