日期:2014-05-17 浏览次数:20765 次
package com.spm.dao; import java.util.List; import org.springframework.orm.hibernate3.support.HibernateDaoSupport; import com.spm.model.Company; /** * 公司抽象类 * @author Administrator * */ public interface CompanyDao{ @SuppressWarnings("unchecked") public List companyNameList(String compName); public Company companyId(Company company); public boolean companyAdd(Company company); public boolean companStopList(String listid); public boolean companUpdate(Company company); public boolean companDelete(Company company); public int companAll(); }
package com.spm.dao.impl; import java.util.List; import javax.management.Query; import org.hibernate.Session; import org.springframework.orm.hibernate3.support.HibernateDaoSupport; import com.spm.dao.CompanyDao; import com.spm.model.Company; /** * 公司实现类 * @author Administrator * */ public class CompanyDaoImpl extends HibernateDaoSupport implements CompanyDao { public boolean companStopList(String listid) { // TODO Auto-generated method stub return false; } public boolean companUpdate(Company company) { // TODO Auto-generated method stub this.getHibernateTemplate().update(company); return false; } public boolean companyAdd(Company company) { System.out.println("添加公司xx"); System.out.println(company.getCompFName()+company.getCompName()); // TODO Auto-generated method stub try { this.getHibernateTemplate().save(company); return true; } catch (Exception e) { // TODO: handle exception e.printStackTrace(); return false; } } public Company companyId(Company company) { // TODO Auto-generated method stub String Hql="from Company where compId=?"; Object[] value={company.getCompId()}; Company company2=(Company) this.getHibernateTemplate().find(Hql,value).get(0); return company2; } public List companyNameList(String compName) { // TODO Auto-generated method stub String hql="from Company where compFName like ? or compName like ?"; //String hql="from Company where compFName like %"+compName+"% or compName like %"+compName+"%"; org.hibernate.Query query =this.getSession().createQuery(hql); query.setString(0,"%"+compName+"%"); query.setString(1,"%"+compName+"%"); List list=query.list(); return list; } /** * 刪除公司 * @param company * @return */ public boolean companDelete(Company company) { // TODO Auto-generated method stub System.out.println("删除公司xx"); try { this.getHibernateTemplate().delete(company); return true; } catch (Exception e) { // TODO: handle exception } return false; } public List<Company> companPage(int pageNo,int pagesize){ String Hql="from Company"; Session session=this.getSession(); List list =session.createQuery(Hql).setFirstResult((pageNo-1)*10).setMaxResults(pagesize).list(); //this.getSession().close(); session.close(); return list; } /** * 查詢所有公司 */ public int companAll(){ String Hql="f