springboot:接收date类型的参数

今天有个postmapping方法,地址都正确,就是死活进不去,真是奇怪了。

终于从日志中得出些端倪,见下:

image

只有这个属性报错,恰恰这个属性是Date型。

这句话说得更清楚:

"defaultMessage":"Failed to convert property value of type 'java.lang.String' to required type 'java.util.Date' for property 'expireTime'; nested exception is org.springframework.core.convert.ConversionFailedException: Failed to convert from type [java.lang.String] to type [@com.alibaba.fastjson.annotation.JSONField java.util.Date] for value '2018-06-29'; nested exception is java.lang.IllegalArgumentException",

查找资料,说只要在字段上加上注解:@DateTimeFormat(pattern="yyyy-MM-dd")

image

加上后就一切OK了。

猜你喜欢

转载自www.cnblogs.com/huiy/p/9047613.html
今日推荐