Impl
public class BaseDAOImpl extends HibernateDaoSupport implements IBaseDAO
//添加数据
this.getHibernateTemplate().save(achi);
//删除
this.getHibernateTemplate().delete(this.getById(achi));
//查询所有
return this.getHibernateTemplate().find("from Achievement a order by a.achieveRate desc");
//查询单个
return (Achievement)this.getHibernateTemplate().get(Achievement.class, id);
//修改
this.getHibernateTemplate().update(achi);
//页面显示
<logic:notEmpty name="list">
<logic:iterate id="obj" name="list">
<tr>
<td>${obj.salerName }</td>
<td>${obj.planAmount }</td>
<td>${obj.factAmount }</td>
<td>${obj.achieveRate }</td>
<td><a href="achi.do?item.id=${obj.id }&opt=doDel">删除</a></td>
<td><a href="achi.do?item.id=${obj.id }&opt=toUpdate">修改</a></td>
</tr>
</logic:iterate>
</logic:notEmpty>
//页面添加
<html:form action="/achi">
<html:hidden property="opt" value="doAdd"/>
销售员 : <html:text property="item.salerName"/><br/>
计划完成 : <html:text property="item.planAmount"/><br/>
实际完成 : <html:text property="item.factAmount"/><br/>
<html:submit/><html:cancel/>
</html:form>
//页面修改
<html:form action="/achi">
<html:hidden property="opt" value="doUpdate"/>
<html:hidden styleId="id" property="item.id"/>
销售员 : <html:text styleId="salerName" property="item.salerName"/><br/>
计划完成 : <html:text styleId="planAmount" property="item.planAmount"/><br/>
实际完成 : <html:text styleId="factAmount" property="item.factAmount"/><br/>
<html:submit/><html:cancel/>
</html:form>
//查询所有Action类
request.setAttribute("list", baseDAO.getAllAchi());
return mapping.findForward("golist");
//添加数据 Action类
baseDAO.addAchi(achiForm.getItem());
return mapping.findForward("godoFind");
//删除Action
baseDAO.delAchi(achiForm.getItem().getId());
return mapping.findForward("godoFind");
// 单个查询Action
Achievement a = baseDAO.getById(achiForm.getItem().getId());
achiForm.setItem(a);
return mapping.findForward("goupdate");
//修改Action
baseDAO.updateAchi(achiForm.getItem());
return mapping.findForward("togoindex");
//Applictioncontext配置
<bean id="baseDAO" class="com.accp.dao.BaseDAOImpl">
<property name="sessionFactory" ref="sessionFactory"></property>
</bean>
<bean name="/achi" class="com.accp.web.action.AchiAction">
<property name="baseDAO" ref="baseDAO"></property>
</bean>
//struts-config配置
org.springframework.web.struts.DelegatingActionProxy
//web.xml配置
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<script type="text/javascript">
function dele()
{
if(confirm("你确定删除吗?"))
{
return true;
}
else
{
return false;
}
}
</script>
οnclick="return dele()"
οnmοuseοver="currentcolor=this.style.backgroundColor; this.style.backgroundColor='D1D1D1'" οnmοuseοut="this.style.backgroundColor=currentcolor"