【发布时间】:2014-06-28 02:14:41
【问题描述】:
我有一个添加学生的表格。对于出生日期,我想使用 kendo ui datepicker,但我不知道控制器如何与模型进行绑定。如果日期选择器的名称属性与类元素匹配,则出现以下错误:The request sent by the client was syntactically incorrect. 如果日期选择器的名称属性不同,则在单击保存按钮时,学生将插入数据库,但使用字段出生日期为空。
下面是jsp文件、控制器和Student类的内容。
我做错了什么?
jsp文件
<div id="addStudent" class="space">
<div class="page-title">Add student</div>
<form:form commandName="addForm" method="post">
<div class="editor-field">
<label for="firstName">First name</label> <input
class="input k-popup k-list-container k-group k-reset" type="text"
name="firstName" />
</div>
<div class="editor-field">
<label for="lastName">Last name</label> <input
class="input k-popup k-list-container k-group k-reset" type="text"
name="lastName" />
</div>
<div class="editor-field">
<label for="dateOfBirth">Date of birth</label>
<kendo:datePicker name="dateOfBirth"></kendo:datePicker> //name attribute
</div>
<div class="editor-field left form-actions">
<a href="http://localhost:8080/GasfProject/gasf/main/menu/students"
class="k-button">Cancel</a>
<input class="k-button" type="submit" name="add" value="Save">
</div>
</form:form>
</div>
控制器
@RequestMapping(value = "/menu/addStudent", method = RequestMethod.POST)
public String addStudent(@ModelAttribute("addForm") Student model) {
logger.debug("Received request in add student post");
// insert in database
StudentDatabaseAccess.addNewStudent(model);
return "redirect:students";
}
学生
public class Student {
private String firstName;
private String lastName;
private Date dateOfBirth;
//getters and setters
}
【问题讨论】: