1、准备实体类
package com.shenmazong.demotimejson.entity;
import com.fasterxml.jackson.annotation.JsonFormat;
import org.springframework.format.annotation.DateTimeFormat;
import java.util.Date;
/**
* @author 军哥
* @version 1.0
* @description: 测试实体类
* @date 2021/9/1 19:35
*/
public class DataVo {
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
private Date date;
public Date getDate() {
return date;
}
public void setDate(Date date) {
this.date = date;
}
}
2、定义congtroller
package com.shenmazong.demotimejson.entity;
import com.fasterxml.jackson.annotation.JsonFormat;
import org.springframework.format.annotation.DateTimeFormat;
import java.util.Date;
/**
* @author 军哥
* @version 1.0
* @description: 测试实体类
* @date 2021/9/1 19:35
*/
public class DataVo {
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
private Date date;
public Date getDate() {
return date;
}
public void setDate(Date date) {
this.date = date;
}
}
3、postman测试

4、日志输出
date1:Thu Sep 02 05:03:06 CST 2021
date2:2021-09-02 05:03:06
