SSH_框架整合3-删除
Posted noaman_wgs
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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 }
(2)EmployeeService.java中:
1 //2删除 2 public void delete(Integer id){ 3 employeeDao.delete(id); 4 }
(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 }
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>
3 完善emp-list.jsp
1 <td> 2 <a href="emp-delete?id=${id }">Delete</a> 3 </td>
以上是关于SSH_框架整合3-删除的主要内容,如果未能解决你的问题,请参考以下文章