67,513
社区成员
发帖
与我相关
我的任务
分享
<a href='<%=path() %>/ssh.do?action=deleteById&id=<bean:write name="rd" property="id" />'>删除</a>
public ActionForward deleteById(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) {
sshService.delelteById(Integer.parseInt(request.getParameter("id")));
return mapping.findForward("toIndex");
}
<action path="/ssh"
type="org.springframework.web.struts.DelegatingActionProxy"
name="sshForm" parameter="action">
<forward name="toList" path="/main.jsp"></forward>
<forward name="toIndex" path="/index.jsp"></forward>
</action>
public class SshDaoImpl extends HibernateDaoSupport implements ISshDao {
public void deleteById(String sql, int id) {
this.getSession().beginTransaction();
Query query = this.getSession().createQuery(sql);
query.setInteger(0, id);
query.executeUpdate();
this.getSession().beginTransaction().commit();
this.getSession().close();
}
}
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd">
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource">
<property name="driverClassName"
value="com.mysql.jdbc.Driver">
</property>
<property name="url" value="jdbc:mysql://localhost:3306/blog"></property>
<property name="username" value="root"></property>
<property name="password" value="snje"></property>
</bean>
<bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="dataSource">
<ref bean="dataSource" />
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">
org.hibernate.dialect.MySQLDialect
</prop>
</props>
</property>
<property name="mappingResources">
<list>
<value>com/ssh/pojo/Posts.hbm.xml</value>
</list>
</property>
</bean>
<bean id="sshDAO" class="com.ssh.dao.impl.SshDaoImpl" scope="singleton">
<property name="sessionFactory">
<ref bean="sessionFactory" />
</property>
</bean>
<bean id="sshService" class="com.ssh.service.impl.SshServiceImpl" scope="singleton">
<property name="sshDAO">
<ref bean="sshDAO" />
</property>
</bean>
<bean name="/ssh" class="com.ssh.action.SshAction" scope="prototype">
<property name="sshService">
<ref bean="sshService" />
</property>
</bean>
</beans>