数据库字段时间字段设置类型为datetime时,查询返回值并不是想要的格式。
gmt_create datetime not null comment '创建时间',
gmt_modified datetime not null comment '修改时间',
我们可以采用下面方法处理:
字段format
/**
* 创建时间
*/
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
@JsonFormat(
pattern = "yyyy-MM-dd HH:mm:ss",
timezone = "GMT+8"
)
private Date gmtCreate;
/**
* 修改时间
*/
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
@JsonFormat(
pattern = "yyyy-MM-dd HH:mm:ss",
timezone = "GMT+8"
)
private Date gmtModified;
映射时不要加jdbcType=“DATE”
<result column="gmt_create" property="gmtCreate"/>
<result column="gmt_modified" property="gmtModified"/>