我有一张表格:
<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;
[...]
答案 0 :(得分:2)
最后,现在感谢gerrytan
我在我的Lostcast
课程中添加:
@DateTimeFormat(pattern = "dd/MM/yyyy")
private Date dateDeclaration;