zoukankan      html  css  js  c++  java
  • 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>
  • 相关阅读:
    迅为IMX6ULL开发板-Linux MISC驱动-编写实验程序
    迅为龙芯2K1000开发板快速体验
    迅为3399开发板Android系统-使用strace跟踪系统调用
    迅为imx6ull开发板使用c语言调用shell命令控制led灯
    迅为与龙芯强强联合匠心之作 iTOP-2K1000开发板正式发布
    迅为iTOP3399开发板QT系统PCIE 4G移植-测试程序
    迅为IMX8MM开发板Android编译环境搭建
    bzero和memset函数
    [linux 2021-10-14] linux中启动jar的shell脚本
    重写与重载的区别
  • 原文地址:https://www.cnblogs.com/luffyxin/p/11214573.html
Copyright © 2011-2022 走看看