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();
}
}
 
        

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM