Hibernate+Spring 对DAO的处理实列(8)
来源:未知 责任编辑:责任编辑 发表时间:2014-01-06 18:09 点击:次
"select count(*) from Info as info where info.boardId = '" + boardId +
"'").next()).intValue();
return count;
}
/**
* 通过版块名取得所有记录集合.[表中要有 board_id字段]
* @param BoardId String
* @return Iterator
*/
public Iterator getAllInfosByBoard(String boardId) throws Exception {
Iterator iterator = null;
String queryString = " select info from Info as info where info.boardId='" +
boardId + "' order by info.id desc";
//创建查询
Query query = getHibernateTemplate().createQuery(getSession(), queryString);
//记录生成
List list = query.list();
//把查询到的结果放入迭代器
iterator = list.iterator();
return iterator;
}
/**
* 通过版块名取得记录列表.[表中要有 board_id字段]
* @param BoardId String
* @return Iterator
*/
public Iterator getInfosByBoard(String boardId, int position, int length)throws
Exception {
Iterator iterator = null;
String queryString = " select info from Info as info where info.boardId='" +
boardId + "' order by info.id desc";
//创建查询
Query query = getHibernateTemplate().createQuery(getSession(), queryString);
//设置游标的起始点
query.setFirstResult(position);
//设置游标的长度
query.setMaxResults(length);
//记录生成
List list = query.list();
//把查询到的结果放入迭代器
iterator = list.iterator();
return iterator;
}
/**
* 取符合条件记录总数.[ 表中要有 board_id 字段,title] 模糊查询title
* @return int
* @param String boardId ,String text
*/
public int getInfosCountByBoard(String boardId, String text) throwsException {
int count = 0;
count = ((Integer) getHibernateTemplate().iterate(
相关新闻>>
- 发表评论
-
- 最新评论 更多>>