@JsonFormat和@DateTimeFormat的作用

@DatetimeFormat是将String转换成Date,一般前台给后台传值时用

     /**
     * 计划发送时间
	 */
    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
	private Date sendTime;

@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")  将Date转换成String  一般后台传值给前台时

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

2个注解换着用,跟前端传过来的是对象还是json字符串也有关系

	/**
	 * 计划发送时间
	 */
    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
//    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
	private Date sendTime;

猜你喜欢

转载自blog.csdn.net/qq_39940205/article/details/81940227