MyEclipse(三)

  小学期的实践不知不觉就要结束了。

  项目差不多已经全部完成了,这一次我来细讲一下删除客户信息要怎么做,其实他的操作和保存新增的客户信息差不多。

  首先在前端custInfo.jsp中,有一个删除按钮。

 <s:a href="delectCust.action?cust.id=%{#cust.id}" onClick="return funDelete();">删除</s:a> 

  它通过strust.xml文件作为中间文件来做请求转换:

1 <!-- 删除 -->
2 <action name="delectCust" class="removeCustAction">
3 <result>/jsp/custInfo.jsp</result>
4 </action>

  这个文件中的removeCustAction这个类有对应着applicationContext.xml文件中的相应的名字:

1 <!--配置-删除deleteAction  -->
2     <bean id="removeCustAction" class="com.crm.action.RemoveCustAction">
3         <property name="custService" ref="custService"></property>
4     </bean>

  该配置又对应着RemoveCustAction这个类,也就是删除这个动作的具体实现

 1 package com.crm.action;
 2 
 3 import com.crm.bean.Cust;
 4 import com.crm.service.CustService;
 5 import com.opensymphony.xwork2.ActionSupport;
 6 
 7 @SuppressWarnings("serial")
 8 public class RemoveCustAction extends ActionSupport{
 9 
10     private Cust cust;
11     private CustService custService;
12 
13 public CustService getCustService() {
14         return custService;
15     }
16 
17     public void setCustService(CustService custService) {
18         this.custService = custService;
19     }
20 
21 @SuppressWarnings("unchecked")
22     @Override
23     public String execute() throws Exception {
24         this.custService.removeCustomer(cust);
25         return SUCCESS;
26     }
27 
28 public Cust getCust() {
29     return cust;
30 }
31 
32 public void setCust(Cust cust) {
33     this.cust = cust;
34 }
35 
36 }

  在custDao和custService的两个类中加入语句

 public void removeCustomer(Cust cust); 

  并且在这两个对应的实现文件(impl)中分别加入如下语句

1 public void removeCustomer(Cust cust) {
2         // TODO Auto-generated method stub
3         this.getHibernateTemplate().delete(cust);
4     }
1 public void removeCustomer(Cust cust) {
2         // TODO Auto-generated method stub
3         this.custDao.removeCustomer(cust);
4     }

 

posted @ 2017-07-06 00:07  芒一果  阅读(109)  评论(0编辑  收藏  举报