首页 > 代码库 > SSH_框架整合3-删除

SSH_框架整合3-删除

一、普通删除

1 完善src中 类:

(1)EmployeeDao.java中: 

技术分享
1 //2 删除2     public void delete(Integer id){3         String hql="DELETE FROM Employee e WHERE e.id=?";4         getSession().createQuery(hql).setInteger(0,id).executeUpdate();5     }
View Code

(2)EmployeeService.java中:

技术分享
1 //2删除2     public void delete(Integer id){3         employeeDao.delete(id);4     }
View Code

(3)EmployeeAction.java中:

技术分享
1 //2 删除2     private Integer id;3     public void setId(Integer id) {4         this.id = id;5     }6     public String delete(){7         employeeService.delete(id);8         return SUCCESS;9     }
View Code

2 完善struts.xml

技术分享
 1 <?xml version="1.0" encoding="UTF-8" ?> 2 <!DOCTYPE struts PUBLIC 3     "-//Apache Software Foundation//DTD Struts Configuration 2.3//EN" 4     "http://struts.apache.org/dtds/struts-2.3.dtd"> 5  6 <struts> 7  8     <constant name="struts.enable.DynamicMethodInvocation" value="false" /> 9     <constant name="struts.devMode" value="true" />10 11     <package name="default" namespace="/" extends="struts-default">12         <action name="emp-*" class="employeeAction"13                 method="{1}">14                 <result name="list">/WEB-INF/views/emp-list.jsp</result>15                  <result name="success" type="redirect">/emp-list</result>16         </action>17     </package>18 19 </struts>
View Code

3 完善emp-list.jsp

技术分享
1 <td>2                         <a href="emp-delete?id=${id }">Delete</a>3                     </td>
View Code

 

 

  

SSH_框架整合3-删除