问题复现步骤:

1、提交表单,参数为:

2、接收参数类型为product实体类,如下

3、错误日志如下:

org.springframework.validation.BindException: org.springframework.validation.BeanPropertyBindingResult: 1 errors
Field error in object 'product' on field 'departureTime': rejected value [2020-02-10 09:00]; codes [typeMismatch.product.departureTime,typeMismatch.departureTime,typeMismatch.java.util.Date,typeMismatch]; arguments [org.springframework.context.support.DefaultMessageSourceResolvable: codes [product.departureTime,departureTime]; arguments []; default message [departureTime]]; default message [Failed to convert property value of type 'java.lang.String' to required type 'java.util.Date' for property 'departureTime'; nested exception is org.springframework.core.convert.ConversionFailedException: Failed to convert from type [java.lang.String] to type [java.util.Date] for value '2020-02-10 09:00'; nested exception is java.lang.IllegalArgumentException]

问题分析:

从错误日志中可以看出,是product类的departureTime属性类型从String转换为Date转换错误。

解决方法:

实体类中加日期格式化注解

@DateTimeFormat(pattern="yyyy-MM-dd HH:mm")
private Date creationTime;

spring mvc绑定参数之日期类型转换的更多相关文章

  1. spring mvc绑定参数之 类型转换 有三种方式:

    spring mvc绑定参数之类型转换有三种方式: 1.实体类中加日期格式化注解(上次做项目使用的这种.简单,但有缺点,是一种局部的处理方式,只能在本实体类中使用.方法三是全局的.) @DateTim ...

  2. spring mvc 绑定参数据默认值,是否必传,(RequestParam(value="id",defaultValue="1",required=true) )

    @RequestMapping(value = "/detail", method = RequestMethod.GET) public String newDetail(@Re ...

  3. Spring MVC与表单日期提交的问题

    Spring MVC与表单日期提交的问题 spring mvc 本身并不提供日期类型的解析器,需要手工绑定, 否则会出现非法参数异常. org.springframework.beans.BeanIn ...

  4. Spring MVC接收参数(Map,List,JSON,Date,2个Bean)(记录一次面试惨状)

    题目Spring MVC 接收参数 MapListDate2个BeanJSON Spring MVC接收参数 -Map Spring MVC接收参数 -List Spring MVC接收参数 -dat ...

  5. Spring MVC请求参数绑定 自定义类型转化 和获取原声带额servlet request response信息

    首先还在我们的框架的基础上建立文件 在domian下建立Account实体类 import org.springframework.stereotype.Controller; import org. ...

  6. Spring MVC请求参数绑定

    所谓请求参数绑定,就是在控制器方法中,将请求参数绑定到方法参数上 @RequestParam 绑定单个请求参数到方法参数上 @RequestParam("id") Integer ...

  7. Spring MVC温故而知新 – 参数绑定、转发与重定向、异常处理、拦截器

    请求参数绑定 当用户发送请求时,根据Spring MVC的请求处理流程,前端控制器会请求处理器映射器返回一个处理器,然后请求处理器适配器之心相应的处理器,此时处理器映射器会调用Spring Mvc 提 ...

  8. Spring MVC JSON 实现JsonSerializer Date类型转换

    转载至:http://blog.csdn.net/lantianzhange/article/details/40920933 在Spring MVC中存在两大类的类型转换,一类是Json,一个是Sp ...

  9. spring mvc 复杂参数注入

    过了这么久,又重新把博客拾起来了 来上海工作也已经有将近两周的时间了, 今天在整理项目的时候,遇到了一个关于参数注入的问题 背景: 我的开发前台用的是extjs4,在对后台spring mvc提交表单 ...

随机推荐

  1. 「POJ3613」Cow Relays

    「POJ3613」Cow Relays 传送门 就一个思想:\(N\) 遍 \(\text{Floyd}\) 求出经过 \(N\) 个点的最短路 看一眼数据范围,想到离散化+矩阵快速幂 代码: #in ...

  2. CentOS 下的apache服务器配置与管理

    一.WEB服务器与Apache1.web服务器与网址 2.Apache的历史 3.补充http://www.netcraft.com/可以查看apache服务器的市场占有率同时必须注意的是ngnix, ...

  3. 128、Java面向对象之对象的比较

    01.代码如下: package TIANPAN; class Book { private String title; private double price; public Book(Strin ...

  4. Random Variables

    可测空间(Measurable Space)和测度空间(Measure Space) 集合X,X上的一个σ-algebra A,则(X,A)被称为可测空间(measurable space) 再在A上 ...

  5. pip使用镜像的方法

    http://e.pypi.python.org/这个就是官网了,清华大学提供的 建议非清华大学校内的使用这个镜像: http://e.pypi.python.org/simple(这也是一个http ...

  6. 吴裕雄--天生自然HADOOP操作实验学习笔记:安装zookeeper集群

    实验目的 了解zookeeper的概念和原理 学会安装zookeeper集群并验证 掌握zookeeper命令使用 实验原理 1.Zookeeper介绍 ZooKeeper是一个分布式的,开放源码的分 ...

  7. D. Number Of Permutations 符合条件的排列种类

    D. Number Of Permutations time limit per test 2 seconds memory limit per test 256 megabytes input st ...

  8. mybatis动态参数查询

    参考:https://blog.csdn.net/zbw18297786698/article/details/53727594

  9. nodejs,webpack安装以及初步运用

    nodejs安装: 1.下载:https://nodejs.org/en/download/ 2.安装node-v6.11.3-x64.msi文件,直接默认安装(next……): 3.验证是否完成安装 ...

  10. 构建javascript array包

    //像一个数组添加数组. copyArray = function(inSrcArray,inDestArray){ var i; for(i=0;i<inSrcArray.length;i++ ...