springmvc在表单提交接收date类型参数的时候会报错:Cannot convert value of type [java.lang.String] to required type [java.util.Date] for property 'actionDate'java
1、利用spring的DateTimeFormat注解spring
让springmvc提交表单时正确的接收date类型参数,主要分如下3个步骤:mvc
一、在须要由string转Date的字段上加上DateTimeFormat注解,代码以下:ui
@DateTimeFormat(pattern="yyyy-MM-dd") private Date actionDate;
二、添加joda-time的jar包spa
<dependency>
<groupId>joda-time</groupId>
<artifactId>joda-time</artifactId>
<version>2.3</version>
</dependency>
三、在springmvc配置文件中添加注解映射的支持,代码以下:code
<mvc:annotation-driven />
这种方法我认为是最好的方法。orm
2、自定义Converterblog
3、在controller中使用initBinder注解string