spring boot 2.x参数绑定

application.properties中配置:

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

实体类:

1
2
private Timestamp createTime;
private Date birthday;

第二种解决方案,是在实体类属性上添加注解:

1
2
3
4
5
6
(pattern = "yyyy-MM-dd HH:mm:ss")
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
private Timestamp createTime;
(pattern = "yyyy-MM-dd HH:mm:ss")
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
private Date birthday;