经过了三天的学习,和老师的指导后,我们的客户信息管理系统已经初具模型。我们定义一些通用的dao接口即有利于我们对这些操作的规范,同时呢也算是一个通用的模板吧,这些是常常用的操作,减少了以后工作的开发工作量,同时也可以继承它增加新的操作。代码如下

package com.crm.impl;

import java.util.List;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;
import com.crm.bean.Cust;
import com.crm.dao.CustDao;

public class CustDaoImpl extends HibernateDaoSupport implements CustDao {

public List<Cust> findAllCust() {
// TODO Auto-generated method stub
String hql = "from Cust cust order by cust.id desc";
return (List<Cust>)this.getHibernateTemplate().find(hql);
}

public Cust findCustomerById(Integer id) {
// TODO Auto-generated method stub
Cust cust = (Cust)this.getHibernateTemplate().get(Cust.class, id);
return cust;
}

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

public void savaCustomer(Cust cust) {
// TODO Auto-generated method stub
this.getHibernateTemplate().save(cust);
}

@SuppressWarnings("unchecked")
public List<Cust> findCustByCondition(Cust cust) {
// TODO Auto-generated method stub
StringBuffer strBuffer = new StringBuffer();
String hql = "from Cust cust where 1=1 ";
strBuffer.append(hql);
if(cust == null){
throw new NullPointerException("查询条件不能为空!");
}
if(!"".equals(cust.getCustname())){
String custname = "and custname = '"+cust.getCustname()+"'";
strBuffer.append(custname);
}
if(!"".equals(cust.getCustno())){
String custno= "and custno = '"+cust.getCustno()+"'";
strBuffer.append(custno);
}
if(!"".equals(cust.getTelephone())){

String Telephone="and Telephone = '"+cust.getTelephone()+"' ";
strBuffer.append(Telephone);
}
String orderBy = "order by cust.id desc";
strBuffer.append(orderBy);
List<Cust> custList = this.getHibernateTemplate().find(strBuffer.toString());
//return (List<Cust>)this.getHibernateTemplate().find(strBuffer.toString());
return custList;
}

public void updateCustomer(Cust cust) {
// TODO Auto-generated method stub
this.getHibernateTemplate().update(cust);
}
}

有了这些接口以后,对于我们写action更加方便了,在此就不一一赘述所有的action了。