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了。


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM