spring,get請求中帶date日期格式參數,后台無法轉換的問題


今天遇到個很奇怪的問題。前端 的查詢條件中帶有日期范圍日期的格式 是 yyyy-MM-dd HH:mm 結果后台報錯

org.springframework.validation.BindException: org.springframework.validation.BeanPropertyBindingResult: 2 errors
Field error in object 'taskModel' on field 'createTimeEnd': rejected value [08-12-2019 00:00]; codes [typeMismatch.taskModel.createTimeEnd,typeMismatch.createTimeEnd,typeMismatch.java.util.Date,typeMismatch]; arguments [org.springframework.context.support.DefaultMessageSourceResolvable: codes [taskModel.createTimeEnd,createTimeEnd]; arguments []; default message [createTimeEnd]]; default message [Failed to convert property value of type 'java.lang.String' to required type 'java.util.Date' for property 'createTimeEnd'; nested exception is org.springframework.core.convert.ConversionFailedException: Failed to convert from type [java.lang.String] to type [@com.fasterxml.jackson.annotation.JsonFormat java.util.Date] for value '08-12-2019 00:00'; nested exception is java.lang.IllegalArgumentException]
Field error in object 'taskModel' on field 'createTimeStart': rejected value [07-16-2019 00:00]; codes [typeMismatch.taskModel.createTimeStart,typeMismatch.createTimeStart,typeMismatch.java.util.Date,typeMismatch]; arguments [org.springframework.context.support.DefaultMessageSourceResolvable: codes [taskModel.createTimeStart,createTimeStart]; arguments []; default message [createTimeStart]]; default message [Failed to convert property value of type 'java.lang.String' to required type 'java.util.Date' for property 'createTimeStart'; nested exception is org.springframework.core.convert.ConversionFailedException: Failed to convert from type [java.lang.String] to type [@com.fasterxml.jackson.annotation.JsonFormat java.util.Date] for value '07-16-2019 00:00'; nested exception is java.lang.IllegalArgumentException]

但是其他的請求里面也是這個格式,后台在實體類上面加注解

@JsonFormat(pattern = "yyyy-MM-dd HH:mm")

都是可以接收到並且解析的。

然后我發現,其他的請求是post 類型的,然后 這個是get 請求。

網上查了下發現,要使用  MM/dd/yyyy HH:mm 這種斜杠的格式才行

<el-date-picker
v-model="listQuery.taskDate" value-format="MM/dd/yyyy HH:mm" type="daterange" range-separator="-"
start-placeholder="開始同步時間" end-placeholder="結束同步時間"
class="component-inner-date">
</el-date-picker>


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM