码迷,mamicode.com
首页 > 其他好文 > 详细

短学期所获之2

时间:2017-07-02 16:16:01      阅读:162      评论:0      收藏:0      [点我收藏+]

标签:his   com   java   point   方便   return   check   ==   stl   

  经过了三天的学习,和老师的指导后,我们的客户信息管理系统已经初具模型。我们定义一些通用的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了。

 

短学期所获之2

标签:his   com   java   point   方便   return   check   ==   stl   

原文地址:http://www.cnblogs.com/zhenghaoo/p/7106113.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!