Hibernate+Spring 对DAO的处理实列(2)
来源:未知 责任编辑:责任编辑 发表时间:2014-01-06 18:09 点击:次
///// ///
////////////////////////////////////////////////////////
/**
* 取记录总数
* @return int
*/
public int getInfosCount() throws Exception {
int count = 0;
String queryString = "select count(*) from Info";
count = ((Integer) getHibernateTemplate().iterate(queryString).next()).
intValue();
return count;
}
/**
* 取所有记录集合
* @return Iterator
*/
public Iterator getAllInfos() throws Exception {
Iterator iterator = null;
String queryString = " select info from Info as info order by info.iddesc";
List list = getHibernateTemplate().find(queryString);
iterator = list.iterator();
return iterator;
}
/**
* 取记录集合
* @return Iterator
* @param int position, int length
*/
public Iterator getInfos(int position, int length) throws Exception {
Iterator iterator = null;
String queryString = " select info from Info as info order by info.iddesc";
Query query = getHibernateTemplate().createQuery(getSession(), queryString);
//设置游标的起始点
query.setFirstResult(position);
//设置游标的长度
query.setMaxResults(length);
//记录生成
List list = query.list();
//把查询到的结果放入迭代器
iterator = list.iterator();
return iterator;
}
/**
* 取第一条记录
* @throws Exception
* @return Station
*/
public Info getFirstInfo() throws Exception {
Iterator iterator = null;
Info info = null;
String queryString = "select info from Info as info order by info.iddesc";
Query query = getHibernateTemplate().createQuery(getSession(), queryString);
相关新闻>>
- 发表评论
-
- 最新评论 更多>>