Welcome toVigges Developer Community-Open, Learning,Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
377 views
in Technique[技术] by (71.8m points)

springboot实体类时间字段使用 @JsonFormat不生效?

之前的项目也是用springboot+mybatis做数据查询的,使用

 @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss",timezone="GMT+8")

可以格式化,但是这次我使用springboot+mybatis-plus做数据查询
在实体类时间字段使用

    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss",timezone="GMT+8")
    @TableField(fill = FieldFill.INSERT) // 自动填充
    private Date createTime;

    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss",timezone="GMT+8")
    @TableField(fill = FieldFill.INSERT_UPDATE) // 自动填充
    private Date updateTime;

查询出来

查询所有.....
Test{id=1, name='张三', createTime=Mon Jun 08 19:12:19 GMT+08:00 2020, updateTime=Mon Jun 08 19:12:17 GMT+08:00 2020}
Test{id=2, name='李四', createTime=Mon Jun 08 19:12:21 GMT+08:00 2020, updateTime=Mon Jun 08 19:12:19 GMT+08:00 2020}

在yml配置文件中配置了

jdbc:mysql://localhost:3306/mybatis-plus?useUnicode=true&characterEncoding=utf-8&serverTimezone=Asia/Shanghai

请问下是不是使用mybatis-plus还需要配置什么吗


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

JsonFormat只对json的序列化/反序列化生效(至少jackson里是这个注解
但是貌似你只是toString,肯定不生效


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to Vigges Developer Community for programmer and developer-Open, Learning and Share
...