首页 > 代码库 > Spring mvc 对象的对象的属性如何传到controller层

Spring mvc 对象的对象的属性如何传到controller层

jsp页面的form:

<form class="am-form" id="addForm" action="addStudent" method="post">
<div class="am-g am-margin-top">
<div class="am-u-sm-4 am-u-md-2 am-text-right">学生编号</div>
<div class="am-u-sm-8 am-u-md-4 am-u-end col-end">
<input type="text" name="studentno"/>
</div>
</div>
<div class="am-g am-margin-top">
<div class="am-u-sm-4 am-u-md-2 am-text-right">学生姓名</div>
<div class="am-u-sm-8 am-u-md-4 am-u-end col-end">
<input type="text" name="studentname"/>
</div>
</div>    
<div class="am-g am-margin-top">
<div class="am-u-sm-4 am-u-md-2 am-text-right">学生系别</div>
<div class="am-u-sm-8 am-u-md-4">
<select name="department.departmentid" >

<c:forEach var="department" items="${DEPARTMENTLIST}">
<option value="${department.departmentid}">${department.departmentname}</option>
</c:forEach>
</select>    
</div>
<div class="am-hide-sm-only am-u-md-6">*必填</div>
</div>
</form>
<select name="department.departmentid" >
注意这里不能写成
<select name="departmentid" >

controller层代码:

@RequestMapping("addStudent")
public void addStudent(Student student,HttpServletResponse response){
try {
System.out.println(student);
studentdao.addStudent(student);
response.sendRedirect("listStudent");
} catch (Exception e) {
e.printStackTrace();
}
}

 

Spring mvc 对象的对象的属性如何传到controller层