Hibernate+Spring 对DAO的处理实列(6)
来源:未知 责任编辑:责任编辑 发表时间:2014-01-06 18:09 点击:次
///// 以下部份表中要有特定字段才能Õ?吩诵袪 犠⒉嵯喙貭 ///
///// ///
////////////////////////////////////////////////////////
/**
* 取符合条件记录总数.[ 表中要有 registername 字段]
* @return int
* @param String text
*/
public int getInfosCountByRegisterName(String registerName) throwsException {
int count = 0;
count = ((Integer) getHibernateTemplate().iterate(
"select count(*) from Info as info where info.registername = '" +
registerName + "'").next()).intValue();
return count;
}
/**
* 通过注册名取得一条记录,如有多条,只取第一条.[表中要有 registername字段]
* @param registername String
* @return Info
*/
public Info getInfoByRegisterName(String registerName) throws Exception {
Iterator iterator = null;
Info info = null;
String queryString =
" select info from Info as info where info.registername='" +
registerName + "' order by info.id desc";
//创建查询
Query query = getHibernateTemplate().createQuery(getSession(), queryString);
//记录生成
List list = query.list();
//把查询到的结果放入迭代器
iterator = list.iterator();
if (iterator.hasNext()) {
info = (Info) iterator.next();
}
return info;
}
/**
* 通过注册名取得所有记录集合.[表中要有 registername字段]
* @param registername String
* @return Iterator
*/
public Iterator getAllInfosByRegisterName(String registerName) throws
Exception {
Iterator iterator = null;
String queryString =
" select info from Info as info where info.registername='" +
registerName + "' order by info.id desc";
相关新闻>>
- 发表评论
-
- 最新评论 更多>>