接口接收字符串日期
接口接收参数是日期(Date)类型,但是前端传递的是字符串日期(2019-11-11);
这时调用接口会报错:
XXX Failed to convert property value of type 'java.lang.String' to required type 'java.util.Date' for property XXX
解决:
在对应的参数上注解:@DateTimeFormat
/**
* 考核结束日期
*/
@DateTimeFormat(pattern = "yyyy-MM-dd")
private Date perfEndTm;
这样接口就可以接收字符串类型日期啦。
接口格式化日期返回
增加注解 @JsonFormat(,pattern = "yyyy-MM-dd HH:mm:ss")
@JsonFormat( pattern = "yyyy-MM-dd HH:mm:ss")
private Date inGateTime;