BaseDao常用方法封装

public class Dao  extends HibernateDaoSupport{
	
	public <T> List<T> loadAll(Class<T> clazz){
		return (List<T>)getHibernateTemplate().loadAll(clazz);
	}
	
	public <T> T load(Class<T> clazz,Serializable id){
		return (T) getHibernateTemplate().load(clazz,  id);
	}
	
	public <T> T find(Class<T> clazz, Serializable id){
		return (T)getHibernateTemplate().get(clazz, id);
	}
	
	public <T> List<T> find(String querySql,Object[] params){
		return (List<T>)getHibernateTemplate().find(querySql, params);
	}
	
	public void save(Object entity){
		getHibernateTemplate().save(entity);
	}
	
	public void saveOrUpdate(Object entity){
		getHibernateTemplate().saveOrUpdate(entity);
	}
	
	public <T> void saveCollection(Collection<T> coll){
		for(T entity : coll)
			save(entity);
	}
	
	public void delete(Object entity){
		getHibernateTemplate().delete(entity);
	}
	
	public <T> void deleteAll(Collection<T> entities){
		getHibernateTemplate().deleteAll(entities);
	}
	
	public void update(Object entity){
		getHibernateTemplate().update(entity);
	}
}

你可能感兴趣的:(常用方法)