JavaEE教案 (26)_第1页
JavaEE教案 (26)_第2页
JavaEE教案 (26)_第3页
JavaEE教案 (26)_第4页
JavaEE教案 (26)_第5页
已阅读5页,还剩14页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

1、重庆正大软件学院软件系MVC框架程序设计电子教案重庆正大软件职业技术学院教案(项目类)授课对象系 别软件系本次课学时4学时年级班次大二章节题目第7章 项目编码目的要求(含技能要求)理解客户档案管理模块客户档案增删改查功能的业务流程理解客户档案管理模块客户档案增删改查功能的程序流程通过练习理解SSH的框架组件及运行流程本节重点理解SSH的框架组件及运行流程本节难点理解客户档案管理模块客户档案增删改查功能的业务流程教学方法项目教学法教学用具机房、屏幕广播问题引入通过第六章的详细设计文档,从而引出本次课程。难点与重点讲解方法引导、分析、讲解、实作演示本次课小结课程小结教后礼记讨论、思考题、作业(含实

2、训作业)完成本次课的课堂任务填写实验报告任务介绍(5分钟)根据需求分析和设计实现客户档案管理模块客户档案增加、修改、查询、删除功能。任务解析(50-60分钟)1. 客户档案表映射文件Client.hbm.xml编写2. 客户档案实体映射类Client编写3. 前台客户档案增删改查页面编写4. 后台业务控制器(action类)ClientAction编写5. 客户档案struts文件的配置6. 用dwr框架实现客户编号重复性验证的dwr.xml编写7. 后台业务处理层接口IClientService编写8. 后台业务处理层实现类ClientService编写9. 后台持久化层接口IClientD

3、ao编写10. 后台持久化层实现类ClientDao编写11. Spirng配置文件applicationContext_beans.xml的配置详细步骤1. 客户档案表映射文件Client.hbm.xml编写删除客户时应删除与此客户相关的所有的订货单和进货单信息,与订货单和进货单相关级联关系中cascade属性的配置应该是all-delete-orphan。关键代码如下:<hibernate-mapping><class name="com.zds.slms.domain.Client" table="client"><i

4、d name="id" type="java.lang.Integer"><column name="id" /><generator class="identity" /></id><property name="code" type="string"><column name="code" length="3" not-null="true">&l

5、t;comment>客户编号</comment></column></property><property name="name" type="string"><column name="name" length="50" not-null="true"><comment>客户名称</comment></column></property><property name=&quo

6、t;address" type="string"><column name="address" length="50" not-null="true"><comment>地址</comment></column></property><property name="telephone" type="string"><column name="telephone"

7、length="30" not-null="true"><comment>电话</comment></column></property><property name="email" type="string"><column name="email" length="30"><comment>电子邮件</comment></column></propert

8、y><set name="stockins" table="stockin" inverse="true" lazy="true" fetch="select" cascade="all-delete-orphan"><key><column name="clientid" not-null="true"><comment>进货单</comment></column

9、></key><one-to-many class="com.zds.slms.domain.Stockin" /></set><set name="stockorders" table="stockorder" inverse="true" lazy="true" fetch="select" cascade="all-delete-orphan"><key><column name

10、="clientid" not-null="true"><comment>订货单</comment></column></key><one-to-many class="com.zds.slms.domain.Stockorder" /></set></class></hibernate-mapping>2. 客户档案实体映射类Client编写public class Client implements java.io.Seriali

11、zable private Integer id;private String code;private String name;private String address;private String telephone;private String email;private Set stockins = new HashSet(0);private Set stockorders = new HashSet(0);public Client() public Client(String code, String name, String address, String telephon

12、e) this.code = code; = name;this.address = address;this.telephone = telephone;public Client(String code, String name, String address, String telephone,String email, Set stockins, Set stockorders) this.code = code; = name;this.address = address;this.telephone = telephone;this.email

13、= email;this.stockins = stockins;this.stockorders = stockorders;/省略成员变量的get/set方法3. 前台客户档案增删改查页面编写客户档案新增页面addClient.jsp页面的关键代码如下:<html><head><base href="<%=basePath%>" /><title>客户管理</title><link rel="stylesheet" href="css/main.css"

14、 type="text/css" /><script language="javascript" src="script/main.js"></script><script type='text/javascript' src='dwr/interface/clientAction.js'></script><script type='text/javascript' src='dwr/engine.js'>

15、;</script><script type='text/javascript' src='dwr/util.js'></script><script type="text/javascript">var textCode;var codeChk = false;function init() textCode = document.getElementById("code");textCode.focus();function out_code() codeChk = fa

16、lse;if (trimString(textCode.value).length>0&& trimString(textCode.value).length<4)clientAction.findClientByCode(textCode.value, function(ret)if (ret > 0) show_message("msg_code","0",'输入的编号'+textCode.value+'重复请重新输入!');codeChk = false; else show_mes

17、sage("msg_code", "1", '输入正确!');codeChk = true;); else show_message('msg_code', '0', '编号不能为空且不能超过3位长度!');codeChk = false;function formSubmit() var chk=false;var chkRetName=out_chkMaxLength('name','msg_name','名称小于10位且不能为空!',&#

18、39;10');var chkRetAddress=out_chkMaxLength('address','msg_address','地址小于50位且不能为空!','50');var chkRetPhone=out_chkPhone('phone', 'msg_phone', '电话只能输入11位或12位数字!');var chkRetEmail=out_chkEmail('email','msg_email','EMAIL小于30位

19、且不能为空!',30);if (codeChk && chkRetAddress && chkRetName && chkRetPhone && chkRetEmail)chk = true;return chk;window.onload = init;</script></head><body><p></p><p><font style="font-size: 10pt;">档案管理->客户档案->新增&

20、lt;/font></p><p></p><s:form action="clientAction" method="post" theme="simple" onsubmit="return formSubmit();"><table border="0" cellpadding="1" cellspacing="1" width="95%"><tr><

21、td align="right" width="10%" nowrap="true">客户编号</td><td width="20%"><s:textfield name="client.code" cssClass="TextInput" id="code" onFocus="show_message('msg_code','2','请输入编号');"

22、 onBlur="out_code()"></s:textfield> <DIV style="DISPLAY: show" id="msg_code" class="box_div_right">&nbsp;</DIV> </td><td align="right" width="10%" nowrap="true">客户名称</td><td width=&quo

23、t;20%"><s:textfield name="" cssClass="TextInput" id="name" onFocus="show_message('msg_name','2','请输入名称');" onBlur="out_chkMaxLength('name', 'msg_name', '名称小于10位且不能为空!', 10)"><

24、;/s:textfield> <DIV style="DISPLAY: show" id="msg_name" class="box_div_right">&nbsp;</DIV> </td><td align="right" width="10%">客户Email</td><td width="20%"><s:textfield name="client.email&quo

25、t; cssClass="TextInput" id="email" onFocus="show_message('msg_email','2','请输入EMAIL');" onBlur="out_chkEmail('email', 'msg_email', 'EMAIL小于30位且不能为空!', 30)"></s:textfield> <DIV style="DISPLAY: show

26、" id="msg_email" class="box_div_right">&nbsp;</DIV> </td><td width="10%">&nbsp;</td></tr><tr><td align="right" width="10%" nowrap="true">客户电话</td><td width="20%"&g

27、t;<s:textfield name="client.telephone" cssClass="TextInput" id="phone" onFocus="show_message('msg_phone','2','请输入电话11位或12位数字.');" onBlur="out_chkPhone('phone', 'msg_phone', '电话只能输入11位或12位数字!')">&l

28、t;/s:textfield> <DIV style="DISPLAY: show" id="msg_phone" class="box_div_right">&nbsp;</DIV> </td><td align="right" width="10%" nowrap="true">客户地址</td><td colspan="5"><s:textfield name

29、="client.address" cssClass="TextInput" id="address" onFocus="show_message('msg_address','2','请输入地址');" onBlur="out_chkMaxLength('address','msg_address','地址小于50位且不能为空!','50')"></s:textfield

30、> <DIV style="DISPLAY: show" id="msg_address" class="box_div_right">&nbsp;</DIV> </td></tr></table><p></p><div style="margin-left: 30px; margin-right: 0px"><table border="0" cellpadding="

31、0" cellspacing="0" width="95%"><tr><td width="10%"><s:submit value="保存" cssClass="BtnAction" method="saveClient"></s:submit></td><td width="10%"><input type="button" class=&

32、quot;BtnAction" value="返回" onClick="history.go(-1);"></td><td width="80%">&nbsp;</td></tr></table></div></s:form></body></html>客户档案修改页面updateClient.jsp页面的关键代码如下:<html><head><base href="

33、;<%=basePath%>" /><title>客户档案</title><link rel="stylesheet" href="css/main.css" type="text/css" /><script language="javascript" src="script/main.js"></script><script type='text/javascript' src=&#

34、39;dwr/interface/clientAction.js'></script><script type='text/javascript' src='dwr/engine.js'></script><script type='text/javascript' src='dwr/util.js'></script><script type="text/javascript">var codeChk = false;fun

35、ction formSubmit() var chk = false;var chkRetName=out_chkMaxLength('name','msg_name','名称小于10位且不能为空!','10');var chkRetAddress=out_chkMaxLength('address','msg_address','地址小于50位且不能为空!','50');var chkRetPhone=out_chkPhone('phone',

36、9;msg_phone','电话只能输入11位或12位数字!');var chkRetEmail=out_chkEmail('email','msg_email','EMAIL小于30位且不能为空!',30);if (chkRetAddress && chkRetName && chkRetPhone && chkRetEmail)chk = true;return chk;</script></head><body><s:form

37、action="clientAction" method="post" theme="simple" onsubmit="return formSubmit();"><s:hidden name="client.id"></s:hidden><s:hidden name="client.code"></s:hidden><p></p><p><font style="fon

38、t-size: 10pt;">档案管理->客户档案->修改</font></p><p></p><table border="0" cellpadding="1" cellspacing="1" width="95%"><tr><td align="right" width="10%" nowrap="true">客户编号</td>&l

39、t;td width="20%"><s:textfield name="client.code" disabled="true" cssClass="TextInput"></s:textfield></td><td align="right" width="10%" nowrap="true">客户名称</td><td width="20%"><s:t

40、extfield name="" cssClass="TextInput" id="name" onFocus="show_message('msg_name','2','请输入名称');" onBlur="out_chkMaxLength('name','msg_name','名称小于10位且不能为空!',10)"></s:textfield><DIV

41、style="DISPLAY: show" id="msg_name" class="box_div_right">&nbsp;</DIV></td><td align="right" width="10%">客户Email</td><td width="20%"><s:textfield name="client.email" cssClass="TextInput

42、" id="email" onFocus="show_message('msg_email','2','请输入EMAIL');" onBlur="out_chkEmail('email','msg_email','EMAIL小于30位且不能为空!',30)"></s:textfield> <DIV style="DISPLAY: show" id="msg_email"

43、; class="box_div_right">&nbsp;</DIV></td><td width="10%">&nbsp;</td></tr><tr><td align="right" width="10%" nowrap="true">客户电话</td><td width="20%"><s:textfield name="cl

44、ient.telephone" cssClass="TextInput" id="phone" onFocus="show_message('msg_phone','2','请输入电话11位或12位数字.');" onBlur="out_chkPhone('phone','msg_phone','电话只能输入11位或12位数字!')"></s:textfield> <DIV style=

45、"DISPLAY: show" id="msg_phone" class="box_div_right">&nbsp;</DIV></td><td align="right" width="10%" nowrap="true">客户地址</td><td colspan="5"><s:textfield name="client.address" cssCla

46、ss="TextInput" id="address" onFocus="show_message('msg_address','2','请输入地址');" onBlur="out_chkMaxLength('address','msg_address','地址小于50位且不能为空!','50')"></s:textfield> <DIV style="DISPLAY:

47、show" id="msg_address" class="box_div_right">&nbsp;</DIV></td></tr></table><p></p><div style="margin-left: 30px; margin-right: 0px"><table border="0" cellpadding="0" cellspacing="0" w

48、idth="95%"><tr><td width="10%"><s:submit value="保存" method="updateClient" cssClass="BtnAction"></s:submit></td><td width="10%"><input type="button" class="BtnAction" value="

49、返回" onClick="history.go(-1);"></td><td width="80%">&nbsp;</td></tr></table></div></s:form></body></html>客户档案查询页面client.jsp页面的关键代码如下:<s:form action="clientAction" method="post" theme="sim

50、ple"><p><font style="font-size: 10pt;">档案管理->客户档案</font></p><table border="0" cellpadding="1" cellspacing="1" width="95%"><tr><td align="right" width="10%" nowrap="true"&

51、gt;客户编号</td><td width="20%"><s:textfield name="client.code" cssClass="TextInput"></s:textfield></td><td align="right" width="10%" nowrap="true">客户名称</td><td width="20%"><s:textfie

52、ld name="" cssClass="TextInput"></s:textfield></td><td width="40%">&nbsp;</td></tr><tr><td align="right" width="10%" nowrap="true">&nbsp;</td><td width="20%"

53、>&nbsp;</td><td width="70%" colspan="5">&nbsp;</td></tr></table><p></p><div style="margin-left: 30px; margin-right: 0px"><table border="0" cellpadding="0" cellspacing="0" width=&

54、quot;95%"><tr><td width="10%"><s:submit value="查找" cssClass="BtnAction" method="findClient"></s:submit></td><td width="10%"><input type="button" class="BtnAction" value="新增"

55、 onClick="replaceModulUrl('<%=basePath%>moduls/archive/addClient.jsp');"></td><td width="10%"><input type="button" onClick="deleteRecords('clientAction!deleteClient.action')" value="删除" class="BtnAction&qu

56、ot; /></td><td width="10%"><input type="reset" value="重置" class="BtnAction" /></td><td width="60%">&nbsp;</td></tr></table></div><p></p><div style="margin-left: 30px; ma

57、rgin-right: 0px"><table width="90%" border="1" cellpadding="0" cellspacing="0"><tr><td width="7%" class="td_title">选择</td><td width="7%" class="td_title">修改</td><td width=&q

58、uot;12%" class="td_title">客户编号</td><td width="22%" class="td_title">客户名称</td><td width="17%" class="td_title">客户地址</td><td width="17%" class="td_title">客户电话</td><td width="

59、18%" class="td_title">客户Email</td></tr><s:iterator var="client" value="clients"><tr><td align="center" class="td_border"><input name="clientId" type="checkbox" title="选中后可进行删除操作"

60、value='<s:property value="#client.id" />'></td><td align="center" class="td_border"><a href='clientAction!preUpdateClient.action?client.id=<s:property value="#client.id" />'><img src="image/edit.gif"

61、; border="0"></a></td><td class="td_border"><s:property value="#client.code" /></td><td class="td_border"><s:property value="#" /></td><td class="td_border"><s:property

62、value="#client.address" /></td><td class="td_border"><s:property value="#client.telephone" /></td><td class="td_border"><s:property value="#client.email" /></td></tr></s:iterator></table>

63、</div></s:form>4. 后台业务控制器(action类)ClientAction编写public class ClientAction extends ActionSupport / 客户档案业务处理接口private IClientService clientService;private Client client = new Client();/ 查询结果集private List<Client> clients = new ArrayList<Client>();/ 操作结束后跳转的地址private String finis

64、h_Url;/ 要删除的客户IDprivate String clientId;/客户档案查询public String findClient() clients = clientService.findClient(client);return "findClient"/客户档案保存public String saveClient() clientService.saveClient(client);finish_Url = "clientAction!findClient.action"return "finish"/客户档案删除

65、public String deleteClient() clientService.deleteClient(clientId);finish_Url = "clientAction!findClient.action"return "finish"/客户档案更新public String updateClient() clientService.updateClient(client);finish_Url = "clientAction!findClient.action"return "finish"/客户

66、档案更新前查询public String preUpdateClient() client = clientService.findClient(client).get(0);return "updateClient"/客户档案查询public int findClientByCode(String code) client = new Client();client.setCode(code);clients = clientService.findClient(client);return clients.size();/此处省略成员变量的get/set方法5. 客户档

67、案struts文件的配置在struts.xml配置文件中添加客户档案的相关配置,具体代码请参考任务解析相关内容。6. 用dwr框架实现客户编号重复性验证的dwr.xml编写在Ajax验证配置文件dwr.xml中加入客户编号重复验证,具体代码请参考任务解析相关内容。7. 后台业务处理层接口IClientService编写public interface IClientService public List<Client> findClient(Client client);public void saveClient(Client client);public void delete

68、Client(String clientId);public void updateClient(Client client);8. 后台业务处理层实现类ClientService编写public class ClientService implements IClientService / 客户档案持久化处理接口private IClientDao clientDao; /* * 客户档案查询 */public List<Client> findClient(Client client) return clientDao.findClient(client);/* * 客户档案保

69、存 */public void saveClient(Client client) clientDao.saveClient(client); /* * 客户档案删除 */public void deleteClient(String clientId) clientDao.deleteClient(clientId); /* * 客户档案更新 */public void updateClient(Client client) clientDao.updateClient(client); public IClientDao getClientDao() return clientDao;pu

70、blic void setClientDao(IClientDao clientDao) this.clientDao = clientDao;9. 后台持久化层接口IClientDao编写public interface IClientDao public List<Client> findClient(Client client);public void saveClient(Client client);public void deleteClient(String clientId);public void updateClient(Client client);10. 后

71、台持久化层实现类ClientDao编写public class ClientDao extends HibernateDaoSupport implements IClientDao /客户档案查询public List<Client> findClient(Client client) / 对象查询条件DetachedCriteria criteria = DetachedCriteria.forClass(Client.class);if (null != client) if (null!=client.getId() && String.valueOf(cl

72、ient.getId().trim().length()>0)criteria.add(Restrictions.eq("id", client.getId();if (null!=client.getCode() && String.valueOf(client.getCode().trim().length()>0)criteria.add(Restrictions.eq("code", client.getCode();if (null!=client.getName() && String.valueO

73、f(client.getName().trim().length()>0)criteria.add(Restrictions.like("name",client.getName(),MatchMode.ANYWHERE);return this.getHibernateTemplate().findByCriteria(criteria);/客户档案保存public void saveClient(Client client) this.getHibernateTemplate().save(client);/客户档案删除public void deleteClient(Str

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论