Springboot配置时间格式

方法一:
可以在apllication.property加入下面配置就可以

#时间戳统一转换
spring.jackson.date-format=yyyy-MM-dd HH:mm:ss
spring.jackson.time-zone=GMT+8

方法二:

  @JsonFormat(timezone = "GMT+8",pattern = "yyyy-MM-dd")
  @DateTimeFormat(pattern="yyyy-MM-dd")
  private Date createdDate;
@JsonFormat(timezone = "GMT+8", pattern = "yyyyMMddHHmmss")
private Date createTime;

方法三:
可以在apllication.yml加入下面配置就可以

#时间戳统一转换
spring:
  jackson:
    date-format: yyyy-MM-dd HH:mm:ss
  time-zone: GMT+8

注意:
@JsonIgnoreProperties此注解是类注解,作用是json序列化时将java bean中的一些属性忽略掉,序列化和反序列化都受影响。
@JsonIgnoreProperties(value = { "word" }) 。
@JsonIgnore此注解用于属性或者方法上(最好是属性上),作用和上面的@JsonIgnoreProperties一样。
@JsonSerialize此注解用于属性或者getter方法上,用于在序列化时嵌入我们自定义的代码,比如序列化一个double时在其后面限制两位小数点。
@JsonSerialize(using = CustomDoubleSerialize.class)
@JsonDeserialize此注解用于属性或者setter方法上。
用于在反序列化时可以嵌入我们自定义的代码,类似于上面的
@JsonSerialize
@JsonDeserialize(using = CustomDateDeserialize.class)

猜你喜欢

转载自blog.csdn.net/qq_32447301/article/details/81712266
今日推荐