Spring boot 修改mybatis传入的日期格式
文章目录
springboot项目中使用Timestamp类型变量对应mybatis的Timestamp格式的列
数据库中显示的时间正常,但Spring boot实际获取的时间格式类似于: "time": "2019-12-31T16:10:00.000+0000", 前端需要使用标准显示的格式,比如"2019-12-31 16:10:00".
后端改更容易一些, 只需在Timestamp变量上加一个@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")即可。
完整的Entity如下:
@AllArgsConstructor
@Data
public class PriceReturnEntity {
private String price;
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
private Timestamp time;
}
实际JsonFormat还可以更改时区等等, 这个可以查看我的另一篇blog
评论
登录后参与技术讨论,分享你的经验与见解。
登录 / 注册暂无评论