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>
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 无需6万激活码!GitHub神秘组织3小时极速复刻Manus,手把手教你使用OpenManus搭建本
· Manus爆火,是硬核还是营销?
· 终于写完轮子一部分:tcp代理 了,记录一下
· 别再用vector<bool>了!Google高级工程师:这可能是STL最大的设计失误
· 单元测试从入门到精通