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