表格提交与字段日期

时间:2014-01-04 22:25:52

标签: ajax spring spring-mvc

我有一张表格:

<form:form method="POST" modelAttribute="lostcard" action="enregistrerLostCard" id="formCard_Lost">
[...]
<form:input path="dateDeclaration" type="text"/>
[...]
<input  value="enregistrer" type="button" onclick="saveformAjax()"/>
[...]

其中lostcard是一个字段为日期dateDeclaration的bean。

当我尝试使用ajax

提交此表单时
function saveformAjax() {
$.ajax({
    url : 'enregistrerLostCard',
    type: 'POST',
    data:$('#formCard_Lost').serialize(),
    success : function(responce) {   
        [...]
    }
});

}

但是当我删除<form:input path="dateDeclaration" type="text"/>时,表单会正常提交。

我的控制器:

@RequestMapping(value="/enregistrerLostCard") 
public  @ResponseBody
void enregistrerLostCard(@ModelAttribute(value="lostcard") Lostcard lostcard) { 

    System.out.println("enregistrerLostCard"); 

}

我的Lostcast课程:

@Entity
@Table(name = "lostcard", catalog = "gestion")
public class Lostcard implements java.io.Serializable {

private Integer id;
private String nom;
private String prenom;
private String cin;
private Date dateDeclaration;
private Date dateDuplicata;
private String annexeAdmin;
    [...]

1 个答案:

答案 0 :(得分:2)

最后,现在感谢gerrytan

我在我的Lostcast课程中添加:

@DateTimeFormat(pattern = "dd/MM/yyyy")
private Date dateDeclaration;