返回类型不同:executeFind()方法返回集合,execute()方法返回对象
executeFind
@Override
public List<TCpContact> getCpContactByPage(final Map<String,Object> params,
final int pageNo, final int pageSize) {
List<TCpContact> list=getHibernateTemplate().executeFind(new HibernateCallback<Object>() {
@Override
public Object doInHibernate(Session session) throws HibernateException,SQLException {
Query query =session.createQuery(hql(params));
List<TCpContact> result=query.setFirstResult(((pageNo-1)* pageSize)).setMaxResults(pageSize).list();
return result;
}
});
return list;
}
execute方法
public TblUser login(final String name, final String pass) throws Exception {
return (TblUser)super.getHibernateTemplate().execute(new HibernateCallback(){
public Object doInHibernate(Session s) throws HibernateException, SQLException {
Query q=s.createQuery("from TblUser as u where u.uname=:name and u.upass=:pass");
q.setString("name", name);
q.setString("pass", pass);
return q.list().get(0);
}
});
}