---
title: "springMVC form表单提交---包含时间类型的数据"
author: "feicklpp"
date: "2014-12-01T11:02:02Z"
tags: []
categories: ["Web前端"]
slug: "springmvc-form"
draft: false
lastmod: "2014-12-01T11:02:02Z"
id: 2162080
url: "https://feicklpp.iteye.com/blog/2162080"
---

当form表单中的数据是基本类型的时，直接请求action中的url，一点问题都没有。

但是当form表单总有时间类型的数据时，且对应的controller是用一个java对象来绑定对应form提交的数据时，就会出现问题。无法提交成功。

解决办法：

在对应的controller中新增下面的方法：


```java

/** 
     * form表单提交 Date类型数据绑定 
     * <功能详细描述> 
     * @param binder 
     * @see [类、类#方法、类#成员] 
     */  
@InitBinder    
public void initBinder(WebDataBinder binder) {    
        SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");    
        dateFormat.setLenient(false);    
        binder.registerCustomEditor(Date.class, new CustomDateEditor(dateFormat, true));    
}  

```