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>
  • 相关阅读:
    WEB-INF目录与META-INF目录的作用
    Spring中的jar包详解
    fatal: Could not read from remote repository.的解决办法
    如何解决failed to push some refs to git
    Spring Boot 集成servlet,发布为可直接运行的war包,方便后续打包为docker镜像。
    使用IntelliJ IDEA,gradle开发Java web应用步骤
    git 命令使用常见问题
    自己动手搭建Git服务器-Gitblit
    windows 安装git
    springMVC 接收数组参数,mybatis 接收数组参数,mybatis批量插入/批量删除案例
  • 原文地址:https://www.cnblogs.com/luffyxin/p/11214573.html
Copyright © 2011-2022 走看看