import java.sql.SQLException;import java.util.List;import java.util.Map;import java.util.Map.Entry;import org.hibernate.HibernateException;import org.hibernate.Query;import org.hibernate.Session;import org.springframework.orm.hibernate3.HibernateCallback;import org.springframework.orm.hibernate3.support.HibernateDaoSupport;public class SealDaoextends HibernateDaoSupport{ /** * description:hql获取list * @param hql * @param map * @return List * * */ public List getList(final String hql,final Map keyValue)throws Exception{ return getHibernateTemplate().execute(new HibernateCallback
>(){ @Override public List doInHibernate(Session session) throws HibernateException, SQLException { // TODO Auto-generated method stub Query query=session.createQuery(hql); for(Entry entry : keyValue.entrySet()){ query.setParameter(entry.getKey(),entry.getValue()); } return query.list(); } }); } /** * description:hql分页获取list * @param hql * @param map * @param start * @param end * @return List * * */ public List getListByPage(final String hql,final Map keyValue,final Integer start,final Integer end)throws Exception{ return getHibernateTemplate().execute(new HibernateCallback
>(){ @Override public List doInHibernate(Session session) throws HibernateException, SQLException { Query query=session.createQuery(hql); for(Entry entry : keyValue.entrySet()){ query.setParameter(entry.getKey(),entry.getValue()); } query.setFirstResult(start); query.setMaxResults(end); return query.list(); } }); } /** * description:hql获取POJO * @param hql * @param map * @return POJO * * */ public POJO getOne(final String hql, final Map keyVal) { // TODO Auto-generated method stub return getHibernateTemplate().execute(new HibernateCallback () { @Override public POJO doInHibernate(Session session) throws HibernateException, SQLException { // TODO Auto-generated method stub Query query = session.createQuery(hql); for(Entry entry : keyVal.entrySet()) { query.setParameter(entry.getKey(), entry.getValue()); } return (POJO)query.uniqueResult(); } }); } /** * description:hql更新 * @param hql * @param map * @return * * */ public void update(final String hql, final Map keyVal) { // TODO Auto-generated method stub getHibernateTemplate().execute(new HibernateCallback
hql封装dao_2