编写修改学生的业务代码:
动作1——页面显示学生资料的动作
逻辑查询:
public Student queryStudentById(String sid) {
Transaction transaction=null;
Student s=null;
try{
Session session=MyHibernateSessionFactory.getSessionFactory().getCurrentSession();
transaction=session.beginTransaction();
s=session.get(Student.class, sid);
transaction.commit();
return s;
}catch(Exception e){
e.printStackTrace();
return s;
}finally{
if(transaction!=null){
transaction=null;
}
}
}
Action动作:
public String modify(){
String sid=request.getParameter("sid");
StudentDao sd=new StudentDaoImpl();
Student s=sd.queryStudentById("sid");
session.setAttribute("student_modify", s);
return "student_modify_success";
}
页面显示学生资料:
<form name="modifyForm" action="<%=path%>/students/Students_save.action" method="post">
<table width="400" >
<tr>
<td width="30%">学号:</td>
<td><input type="text" name="sid" value='<s:property value="#session.student_modify.sid"/>' readonly="readonly"/></td>
</tr>
<tr>
<td width="30%">姓名:</td>
<td><input type="text" name="sname" value='<s:property value="#session.student_modify.sname"/>'/></td>
</tr>
<tr>
<td>性别:</td>
<td>
<s:if test='%{#session.student_modify.gender=="男"}'>
<input type="radio" name="gender" value="男" checked="checked"/>男
<input type="radio" name="gender" value="女"/>女
</s:if>
<s:else>
<input type="radio" name="gender" value="男" />男
<input type="radio" name="gender" value="女" checked="checked"/>女
</s:else>
</td>
</tr>
<tr>
<td>出生日期:</td>
<td><input name="birthday" type="text" id="control_date" size="20"
maxlength="10" onclick="new Calendar().show(this);" readonly="readonly"
value="<s:date name="#session.student_modify.birthday" format="yyyy-MM-dd"/>"
/>
</td>
</tr>
<tr>
<td>地址:</td>
<td><input type="text" name="address" value='<s:property value="#session.student_modify.address"/>'/></td>
</tr>
<tr>
<td colspan="2" align="center"><input class="button" type="submit" value="修改"></td>
</tr>
</table>
</form>
动作2——保存修改后的学生资料的动作