package
common.dao;
![](https://i-blog.csdnimg.cn/blog_migrate/6810355c2f78c12e91b7997a8e8c583a.gif)
import
java.util.
*
;
![](https://i-blog.csdnimg.cn/blog_migrate/6810355c2f78c12e91b7997a8e8c583a.gif)
import
net.sf.hibernate.
*
;
import
org.springframework.orm.hibernate.support.
*
;
![](https://i-blog.csdnimg.cn/blog_migrate/6810355c2f78c12e91b7997a8e8c583a.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/6810355c2f78c12e91b7997a8e8c583a.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/a41954a27d6ad96fa2c2cf816e677448.gif)
/** */
/**
* <p>Title: </p>
* <p>Description: </p>
* <p>Copyright: Copyright (c) 2004</p>
* <p>Company: </p>
* @author 段洪杰
* @version 1.0
*/
![](https://i-blog.csdnimg.cn/blog_migrate/6810355c2f78c12e91b7997a8e8c583a.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/a41954a27d6ad96fa2c2cf816e677448.gif)
public
class
BaseDAOImpl
extends
HibernateDaoSupport
implements
IBaseDAO
...
{
![](https://i-blog.csdnimg.cn/blog_migrate/6a9c071a08f1dae2d3e1c512000eef41.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/6a9c071a08f1dae2d3e1c512000eef41.gif)
private Class pojoClass;
![](https://i-blog.csdnimg.cn/blog_migrate/6a9c071a08f1dae2d3e1c512000eef41.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/37c8bf68cdc3cc81759c34160776bc53.gif) /** *//**
* 构造函数
*/
![](https://i-blog.csdnimg.cn/blog_migrate/6a9c071a08f1dae2d3e1c512000eef41.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/37c8bf68cdc3cc81759c34160776bc53.gif) public BaseDAOImpl() ...{
super();
}
![](https://i-blog.csdnimg.cn/blog_migrate/6a9c071a08f1dae2d3e1c512000eef41.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/37c8bf68cdc3cc81759c34160776bc53.gif) /** *//**
* 构造函数
*/
![](https://i-blog.csdnimg.cn/blog_migrate/37c8bf68cdc3cc81759c34160776bc53.gif) public BaseDAOImpl(Class pojoClass) ...{
super();
this.pojoClass=pojoClass;
}
![](https://i-blog.csdnimg.cn/blog_migrate/6a9c071a08f1dae2d3e1c512000eef41.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/37c8bf68cdc3cc81759c34160776bc53.gif) /** *//**
* 增加记录
* @param object Object
*/
![](https://i-blog.csdnimg.cn/blog_migrate/37c8bf68cdc3cc81759c34160776bc53.gif) public void setObject(Object object) throws Exception ...{
getHibernateTemplate().save(object);
}
![](https://i-blog.csdnimg.cn/blog_migrate/6a9c071a08f1dae2d3e1c512000eef41.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/6a9c071a08f1dae2d3e1c512000eef41.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/37c8bf68cdc3cc81759c34160776bc53.gif) /** *//**
* 通过ID取得记录
* @param id String
* @return Object
*/
![](https://i-blog.csdnimg.cn/blog_migrate/37c8bf68cdc3cc81759c34160776bc53.gif) public Object getObjectById(String id) throws Exception ...{
Object object = (Object) getHibernateTemplate().load(pojoClass, id);
return object;
}
![](https://i-blog.csdnimg.cn/blog_migrate/6a9c071a08f1dae2d3e1c512000eef41.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/6a9c071a08f1dae2d3e1c512000eef41.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/37c8bf68cdc3cc81759c34160776bc53.gif) /** *//**
* 修改记录
* @param Object object
*/
![](https://i-blog.csdnimg.cn/blog_migrate/37c8bf68cdc3cc81759c34160776bc53.gif) public void modifyObject(Object object) throws Exception ...{
getHibernateTemplate().update(object);
}
![](https://i-blog.csdnimg.cn/blog_migrate/6a9c071a08f1dae2d3e1c512000eef41.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/6a9c071a08f1dae2d3e1c512000eef41.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/37c8bf68cdc3cc81759c34160776bc53.gif) /** *//**
* 删除记录
* @param Object object
*/
![](https://i-blog.csdnimg.cn/blog_migrate/37c8bf68cdc3cc81759c34160776bc53.gif) public void removeObject(Object object) throws Exception ...{
getHibernateTemplate().delete(object);
}
![](https://i-blog.csdnimg.cn/blog_migrate/6a9c071a08f1dae2d3e1c512000eef41.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/6a9c071a08f1dae2d3e1c512000eef41.gif)
/ ///
/以下部份不带审核功能 ///
/ ///
![](https://i-blog.csdnimg.cn/blog_migrate/6a9c071a08f1dae2d3e1c512000eef41.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/37c8bf68cdc3cc81759c34160776bc53.gif) /** *//**
* 取记录总数
* @return int
*/
![](https://i-blog.csdnimg.cn/blog_migrate/37c8bf68cdc3cc81759c34160776bc53.gif) public int getObjectsCount() throws Exception ...{
int count = 0;
String queryString = "select count(*) from "+pojoClass.getName();
count = ((Integer) getHibernateTemplate().iterate(queryString).next()).
intValue();
return count;
}
![](https://i-blog.csdnimg.cn/blog_migrate/6a9c071a08f1dae2d3e1c512000eef41.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/6a9c071a08f1dae2d3e1c512000eef41.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/37c8bf68cdc3cc81759c34160776bc53.gif) /** *//**
* 取所有记录集合
* @return Iterator
*/
![](https://i-blog.csdnimg.cn/blog_migrate/37c8bf68cdc3cc81759c34160776bc53.gif) public Iterator getAllObjects() throws Exception ...{
Iterator iterator = null;
String queryString = " select "+pojoClass.getName().toLowerCase()+" from "+pojoClass.getName()+" as "+pojoClass.getName().toLowerCase()+" order by "+pojoClass.getName().toLowerCase()+".id desc";
List list = getHibernateTemplate().find(queryString);
iterator = list.iterator();
return iterator;
![](https://i-blog.csdnimg.cn/blog_migrate/6a9c071a08f1dae2d3e1c512000eef41.gif)
}
![](https://i-blog.csdnimg.cn/blog_migrate/6a9c071a08f1dae2d3e1c512000eef41.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/6a9c071a08f1dae2d3e1c512000eef41.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/37c8bf68cdc3cc81759c34160776bc53.gif) /** *//**
* 取记录集合
* @return Iterator
* @param int position, int length
*/
![](https://i-blog.csdnimg.cn/blog_migrate/37c8bf68cdc3cc81759c34160776bc53.gif) public Iterator getObjects(int position, int length) throws Exception ...{
Iterator iterator = null;
String queryString = " select "+pojoClass.getName().toLowerCase()+" from "+pojoClass.getName()+" as "+pojoClass.getName().toLowerCase()+" order by "+pojoClass.getName().toLowerCase()+".id desc";
Query query = getHibernateTemplate().createQuery(getSession(), queryString);
//设置游标的起始点
query.setFirstResult(position);
//设置游标的长度
query.setMaxResults(length);
//记录生成
List list = query.list();
//把查询到的结果放入迭代器
iterator = list.iterator();
return iterator;
}
![](https://i-blog.csdnimg.cn/blog_migrate/6a9c071a08f1dae2d3e1c512000eef41.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/6a9c071a08f1dae2d3e1c512000eef41.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/37c8bf68cdc3cc81759c34160776bc53.gif) /** *//**
* 取第一条记录
* @throws Exception
* @return Station
*/
![](https://i-blog.csdnimg.cn/blog_migrate/37c8bf68cdc3cc81759c34160776bc53.gif) public Object getFirstObject() throws Exception ...{
Iterator iterator = null;
Object object = null;
String queryString = "select "+pojoClass.getName().toLowerCase()+" from "+pojoClass.getName()+" as "+pojoClass.getName().toLowerCase()+" order by "+pojoClass.getName().toLowerCase()+".id desc";
Query query = getHibernateTemplate().createQuery(getSession(), queryString);
//记录生成
List list = query.list();
//把查询到的结果放入迭代器
iterator = list.iterator();
![](https://i-blog.csdnimg.cn/blog_migrate/37c8bf68cdc3cc81759c34160776bc53.gif) if (iterator.hasNext()) ...{
object = (Object) iterator.next();
}
return object;
}
![](https://i-blog.csdnimg.cn/blog_migrate/6a9c071a08f1dae2d3e1c512000eef41.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/6a9c071a08f1dae2d3e1c512000eef41.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/37c8bf68cdc3cc81759c34160776bc53.gif) /** *//**
* 取最后一条记录
* @throws Exception
* @return Station
*/
![](https://i-blog.csdnimg.cn/blog_migrate/37c8bf68cdc3cc81759c34160776bc53.gif) public Object getLastObject() throws Exception ...{
Iterator iterator = null;
Object object = null;
String queryString = "select "+pojoClass.getName().toLowerCase()+" from "+pojoClass.getName()+" as "+pojoClass.getName().toLowerCase()+" order by "+pojoClass.getName().toLowerCase()+".id asc";
Query query = getHibernateTemplate().createQuery(getSession(), queryString);
//记录生成
List list = query.list();
//把查询到的结果放入迭代器
iterator = list.iterator();
![](https://i-blog.csdnimg.cn/blog_migrate/37c8bf68cdc3cc81759c34160776bc53.gif) if (iterator.hasNext()) ...{
object = (Object) iterator.next();
}
return object;
![](https://i-blog.csdnimg.cn/blog_migrate/6a9c071a08f1dae2d3e1c512000eef41.gif)
}
![](https://i-blog.csdnimg.cn/blog_migrate/6a9c071a08f1dae2d3e1c512000eef41.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/6a9c071a08f1dae2d3e1c512000eef41.gif)
/ ///
/ 以下部份表中要有特定字段才能Õ吩诵袪 牳鋈撕推笠禒 ///
/ ///
![](https://i-blog.csdnimg.cn/blog_migrate/6a9c071a08f1dae2d3e1c512000eef41.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/37c8bf68cdc3cc81759c34160776bc53.gif) /** *//**
* 取符合条件记录总数, [表中要有 isperson 字段]
* @return int
* @param int isPerson
*/
![](https://i-blog.csdnimg.cn/blog_migrate/6a9c071a08f1dae2d3e1c512000eef41.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/37c8bf68cdc3cc81759c34160776bc53.gif) public int getObjectsCountByIsperson(int isPerson) throws Exception ...{
int count = 0;
String queryString =
"select count(*) from "+pojoClass.getName()+" as "+pojoClass.getName().toLowerCase()+" where "+pojoClass.getName().toLowerCase()+".isperson =" + isPerson;
count = ((Integer) getHibernateTemplate().iterate(queryString).next()).
intValue();
return count;
}
![](https://i-blog.csdnimg.cn/blog_migrate/6a9c071a08f1dae2d3e1c512000eef41.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/6a9c071a08f1dae2d3e1c512000eef41.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/37c8bf68cdc3cc81759c34160776bc53.gif) /** *//**
* 取所有符合条件记录集合, 模糊查询条件.[表中要有 isperson 字段]
* @return Iterator
* @param int isPerson
*/
![](https://i-blog.csdnimg.cn/blog_migrate/6a9c071a08f1dae2d3e1c512000eef41.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/37c8bf68cdc3cc81759c34160776bc53.gif) public Iterator getAllObjectsByIsperson(int isPerson) throws Exception ...{
Iterator iterator = null;
String queryString = " select "+pojoClass.getName().toLowerCase()+" from "+pojoClass.getName()+" as "+pojoClass.getName().toLowerCase()+" where "+pojoClass.getName().toLowerCase()+".isperson =" +
isPerson + " order by "+pojoClass.getName().toLowerCase()+".id desc";
List list = getHibernateTemplate().find(queryString);
//把查询到的结果放入迭代器
iterator = list.iterator();
return iterator;
}
![](https://i-blog.csdnimg.cn/blog_migrate/6a9c071a08f1dae2d3e1c512000eef41.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/6a9c071a08f1dae2d3e1c512000eef41.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/37c8bf68cdc3cc81759c34160776bc53.gif) /** *//**
* 取符合条件记录集合, 模糊查询条件.[表中要有 isperson 字段]
* @return Iterator
* @param int isPerson,int position, int length
*/
![](https://i-blog.csdnimg.cn/blog_migrate/6a9c071a08f1dae2d3e1c512000eef41.gif)
public Iterator getObjectsByIsperson(int isPerson, int position, int length) throws
![](https://i-blog.csdnimg.cn/blog_migrate/37c8bf68cdc3cc81759c34160776bc53.gif) Exception ...{
Iterator iterator = null;
String queryString = " select "+pojoClass.getName().toLowerCase()+" from "+pojoClass.getName()+" as "+pojoClass.getName().toLowerCase()+" where "+pojoClass.getName().toLowerCase()+".isperson =" +
isPerson + " order by "+pojoClass.getName().toLowerCase()+".id desc";
//创建查询
Query query = getHibernateTemplate().createQuery(getSession(), queryString);
//设置游标的起始点
query.setFirstResult(position);
//设置游标的长度
query.setMaxResults(length);
//记录生成
List list = query.list();
//把查询到的结果放入迭代器
iterator = list.iterator();
return iterator;
}
![](https://i-blog.csdnimg.cn/blog_migrate/6a9c071a08f1dae2d3e1c512000eef41.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/6a9c071a08f1dae2d3e1c512000eef41.gif)
/ ///
/ 以下部份表中要有特定字段才能Õ吩诵袪 查询部份 ///
/ ///
///
![](https://i-blog.csdnimg.cn/blog_migrate/37c8bf68cdc3cc81759c34160776bc53.gif) /** *//**
* 取符合条件记录总数, 模糊查询条件.[表中要有 title 字段]
* @return int
* @param String text
*/
![](https://i-blog.csdnimg.cn/blog_migrate/37c8bf68cdc3cc81759c34160776bc53.gif) public int getObjectsCount(String text) throws Exception ...{
int count = 0;
count = ((Integer) getHibernateTemplate().iterate(
"select count(*) from "+pojoClass.getName()+" as "+pojoClass.getName().toLowerCase()+" where "+pojoClass.getName().toLowerCase()+".title like '%" + text +"%'").next()).intValue();
return count;
}
![](https://i-blog.csdnimg.cn/blog_migrate/6a9c071a08f1dae2d3e1c512000eef41.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/6a9c071a08f1dae2d3e1c512000eef41.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/37c8bf68cdc3cc81759c34160776bc53.gif) /** *//**
* 取所有符合条件记录集合, 模糊查询条件.[表中要有 title 字段]
* @return Iterator
* @param String text
*/
![](https://i-blog.csdnimg.cn/blog_migrate/6a9c071a08f1dae2d3e1c512000eef41.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/37c8bf68cdc3cc81759c34160776bc53.gif) public Iterator getAllObjects(String text) throws Exception ...{
Iterator iterator = null;
String queryString =
" select "+pojoClass.getName().toLowerCase()+" from "+pojoClass.getName()+" as "+pojoClass.getName().toLowerCase()+" where "+pojoClass.getName().toLowerCase()+".title like '%" + text +
"%' order by "+pojoClass.getName().toLowerCase()+".id desc";
//创建查询
Query query = getHibernateTemplate().createQuery(getSession(), queryString);
//记录生成
List list = query.list();
//把查询到的结果放入迭代器
iterator = list.iterator();
return iterator;
}
![](https://i-blog.csdnimg.cn/blog_migrate/6a9c071a08f1dae2d3e1c512000eef41.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/6a9c071a08f1dae2d3e1c512000eef41.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/37c8bf68cdc3cc81759c34160776bc53.gif) /** *//**
* 取符合条件记录集合, 模糊查询条件.[表中要有 title 字段]
* @return Iterator
* @param String text,int position, int length
*/
public Iterator getObjects(String text, int position, int length) throws
![](https://i-blog.csdnimg.cn/blog_migrate/37c8bf68cdc3cc81759c34160776bc53.gif) Exception ...{
Iterator iterator = null;
String queryString =
" select "+pojoClass.getName().toLowerCase()+" from "+pojoClass.getName()+" as "+pojoClass.getName().toLowerCase()+" where "+pojoClass.getName().toLowerCase()+".title like '%" + text +
"%' order by "+pojoClass.getName().toLowerCase()+".id desc";
![](https://i-blog.csdnimg.cn/blog_migrate/6a9c071a08f1dae2d3e1c512000eef41.gif)
//创建查询
Query query = getHibernateTemplate().createQuery(getSession(), queryString);
//设置游标的起始点
query.setFirstResult(position);
//设置游标的长度
query.setMaxResults(length);
//记录生成
List list = query.list();
//把查询到的结果放入迭代器
iterator = list.iterator();
return iterator;
}
![](https://i-blog.csdnimg.cn/blog_migrate/6a9c071a08f1dae2d3e1c512000eef41.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/6a9c071a08f1dae2d3e1c512000eef41.gif)
/ ///
/ 以下部份表中要有特定字段才能Õ吩诵袪 犠⒉嵯喙貭 ///
/ ///
![](https://i-blog.csdnimg.cn/blog_migrate/6a9c071a08f1dae2d3e1c512000eef41.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/37c8bf68cdc3cc81759c34160776bc53.gif) /** *//**
* 取符合条件记录总数.[ 表中要有 registername 字段]
* @return int
* @param String text
*/
![](https://i-blog.csdnimg.cn/blog_migrate/37c8bf68cdc3cc81759c34160776bc53.gif) public int getObjectsCountByRegisterName(String registerName) throws Exception ...{
int count = 0;
count = ((Integer) getHibernateTemplate().iterate(
"select count(*) from "+pojoClass.getName()+" as "+pojoClass.getName().toLowerCase()+" where "+pojoClass.getName().toLowerCase()+".registername = '" +
registerName + "'").next()).intValue();
return count;
}
![](https://i-blog.csdnimg.cn/blog_migrate/6a9c071a08f1dae2d3e1c512000eef41.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/6a9c071a08f1dae2d3e1c512000eef41.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/37c8bf68cdc3cc81759c34160776bc53.gif) /** *//**
* 通过注册名取得一条记录,如有多条,只取第一条.[表中要有 registername字段]
* @param registername String
* @return Object
*/
![](https://i-blog.csdnimg.cn/blog_migrate/37c8bf68cdc3cc81759c34160776bc53.gif) public Object getObjectByRegisterName(String registerName) throws Exception ...{
Iterator iterator = null;
Object object = null;
String queryString =
" select "+pojoClass.getName().toLowerCase()+" from "+pojoClass.getName()+" as "+pojoClass.getName().toLowerCase()+" where "+pojoClass.getName().toLowerCase()+".registername='" +
registerName + "' order by "+pojoClass.getName().toLowerCase()+".id desc";
//创建查询
Query query = getHibernateTemplate().createQuery(getSession(), queryString);
//记录生成
List list = query.list();
//把查询到的结果放入迭代器
iterator = list.iterator();
![](https://i-blog.csdnimg.cn/blog_migrate/37c8bf68cdc3cc81759c34160776bc53.gif) if (iterator.hasNext()) ...{
object = (Object) iterator.next();
}
return object;
}
![](https://i-blog.csdnimg.cn/blog_migrate/6a9c071a08f1dae2d3e1c512000eef41.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/6a9c071a08f1dae2d3e1c512000eef41.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/37c8bf68cdc3cc81759c34160776bc53.gif) /** *//**
* 通过注册名取得所有记录集合.[表中要有 registername字段]
* @param registername String
* @return Iterator
*/
public Iterator getAllObjectsByRegisterName(String registerName) throws
![](https://i-blog.csdnimg.cn/blog_migrate/37c8bf68cdc3cc81759c34160776bc53.gif) Exception ...{
Iterator iterator = null;
String queryString =
" select "+pojoClass.getName().toLowerCase()+" from "+pojoClass.getName()+" as "+pojoClass.getName().toLowerCase()+" where "+pojoClass.getName().toLowerCase()+".registername='" +
registerName + "' order by "+pojoClass.getName().toLowerCase()+".id desc";
//创建查询
Query query = getHibernateTemplate().createQuery(getSession(), queryString);
//记录生成
List list = query.list();
//把查询到的结果放入迭代器
iterator = list.iterator();
return iterator;
}
![](https://i-blog.csdnimg.cn/blog_migrate/6a9c071a08f1dae2d3e1c512000eef41.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/6a9c071a08f1dae2d3e1c512000eef41.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/37c8bf68cdc3cc81759c34160776bc53.gif) /** *//**
* 通过注册名取得记录列表.[表中要有 registername字段]
* @param registername String
* @return Iterator
*/
public Iterator getObjectsByRegisterName(String registerName, int position,
![](https://i-blog.csdnimg.cn/blog_migrate/37c8bf68cdc3cc81759c34160776bc53.gif) int length) throws Exception ...{
Iterator iterator = null;
String queryString =
" select "+pojoClass.getName().toLowerCase()+" from "+pojoClass.getName()+" as "+pojoClass.getName().toLowerCase()+" where "+pojoClass.getName().toLowerCase()+".registername='" +
registerName + "' order by "+pojoClass.getName().toLowerCase()+".id desc";
//创建查询
Query query = getHibernateTemplate().createQuery(getSession(), queryString);
//设置游标的起始点
query.setFirstResult(position);
//设置游标的长度
query.setMaxResults(length);
//记录生成
List list = query.list();
//把查询到的结果放入迭代器
iterator = list.iterator();
return iterator;
}
![](https://i-blog.csdnimg.cn/blog_migrate/6a9c071a08f1dae2d3e1c512000eef41.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/6a9c071a08f1dae2d3e1c512000eef41.gif)
/ ///
/ 以下部份表中要有特定字段才能Õ吩诵袪 犑餍桶婵闋 ///
/ ///
![](https://i-blog.csdnimg.cn/blog_migrate/6a9c071a08f1dae2d3e1c512000eef41.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/37c8bf68cdc3cc81759c34160776bc53.gif) /** *//**
* 取记录总数.[ 表中要有 board_id 字段]
* @return int
* @param String boardId
*/
![](https://i-blog.csdnimg.cn/blog_migrate/37c8bf68cdc3cc81759c34160776bc53.gif) public int getObjectsCountByBoard(String boardId) throws Exception ...{
int count = 0;
![](https://i-blog.csdnimg.cn/blog_migrate/6a9c071a08f1dae2d3e1c512000eef41.gif)
count = ((Integer) getHibernateTemplate().iterate(
"select count(*) from "+pojoClass.getName()+" as "+pojoClass.getName().toLowerCase()+" where "+pojoClass.getName().toLowerCase()+".boardId = '" + boardId +
"'").next()).intValue();
![](https://i-blog.csdnimg.cn/blog_migrate/6a9c071a08f1dae2d3e1c512000eef41.gif)
return count;
}
![](https://i-blog.csdnimg.cn/blog_migrate/6a9c071a08f1dae2d3e1c512000eef41.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/6a9c071a08f1dae2d3e1c512000eef41.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/37c8bf68cdc3cc81759c34160776bc53.gif) /** *//**
* 通过版块名取得所有记录集合.[表中要有 board_id字段]
* @param BoardId String
* @return Iterator
*/
![](https://i-blog.csdnimg.cn/blog_migrate/37c8bf68cdc3cc81759c34160776bc53.gif) public Iterator getAllObjectsByBoard(String boardId) throws Exception ...{
Iterator iterator = null;
String queryString = " select "+pojoClass.getName().toLowerCase()+" from "+pojoClass.getName()+" as "+pojoClass.getName().toLowerCase()+" where "+pojoClass.getName().toLowerCase()+".boardId='" +
boardId + "' order by "+pojoClass.getName().toLowerCase()+".id desc";
//创建查询
Query query = getHibernateTemplate().createQuery(getSession(), queryString);
//记录生成
List list = query.list();
//把查询到的结果放入迭代器
iterator = list.iterator();
return iterator;
}
![](https://i-blog.csdnimg.cn/blog_migrate/6a9c071a08f1dae2d3e1c512000eef41.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/6a9c071a08f1dae2d3e1c512000eef41.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/37c8bf68cdc3cc81759c34160776bc53.gif) /** *//**
* 通过版块名取得记录列表.[表中要有 board_id字段]
* @param BoardId String
* @return Iterator
*/
public Iterator getObjectsByBoard(String boardId, int position, int length) throws
![](https://i-blog.csdnimg.cn/blog_migrate/37c8bf68cdc3cc81759c34160776bc53.gif) Exception ...{
Iterator iterator = null;
String queryString = " select "+pojoClass.getName().toLowerCase()+" from "+pojoClass.getName()+" as "+pojoClass.getName().toLowerCase()+" where "+pojoClass.getName().toLowerCase()+".boardId='" +
boardId + "' order by "+pojoClass.getName().toLowerCase()+".id desc";
![](https://i-blog.csdnimg.cn/blog_migrate/6a9c071a08f1dae2d3e1c512000eef41.gif)
//创建查询
Query query = getHibernateTemplate().createQuery(getSession(), queryString);
//设置游标的起始点
query.setFirstResult(position);
//设置游标的长度
query.setMaxResults(length);
//记录生成
List list = query.list();
//把查询到的结果放入迭代器
iterator = list.iterator();
![](https://i-blog.csdnimg.cn/blog_migrate/6a9c071a08f1dae2d3e1c512000eef41.gif)
return iterator;
![](https://i-blog.csdnimg.cn/blog_migrate/6a9c071a08f1dae2d3e1c512000eef41.gif)
}
![](https://i-blog.csdnimg.cn/blog_migrate/6a9c071a08f1dae2d3e1c512000eef41.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/6a9c071a08f1dae2d3e1c512000eef41.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/37c8bf68cdc3cc81759c34160776bc53.gif) /** *//**
* 取符合条件记录总数.[ 表中要有 board_id 字段,title] 模糊查询title
* @return int
* @param String boardId ,String text
*/
![](https://i-blog.csdnimg.cn/blog_migrate/37c8bf68cdc3cc81759c34160776bc53.gif) public int getObjectsCountByBoard(String boardId, String text) throws Exception ...{
int count = 0;
![](https://i-blog.csdnimg.cn/blog_migrate/6a9c071a08f1dae2d3e1c512000eef41.gif)
count = ((Integer) getHibernateTemplate().iterate(
"select count(*) from "+pojoClass.getName()+" as "+pojoClass.getName().toLowerCase()+" where "+pojoClass.getName().toLowerCase()+".boardId='" + boardId +
"' and "+pojoClass.getName().toLowerCase()+".title like '%" + text + "%'").next()).intValue();
![](https://i-blog.csdnimg.cn/blog_migrate/6a9c071a08f1dae2d3e1c512000eef41.gif)
return count;
![](https://i-blog.csdnimg.cn/blog_migrate/6a9c071a08f1dae2d3e1c512000eef41.gif)
}
![](https://i-blog.csdnimg.cn/blog_migrate/6a9c071a08f1dae2d3e1c512000eef41.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/6a9c071a08f1dae2d3e1c512000eef41.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/37c8bf68cdc3cc81759c34160776bc53.gif) /** *//**
* 通过版块名取得记录列表.[表中要有 board_id字段] 模糊查询title
* @param String boardID,int position, int length
* @return Iterator
*/
public Iterator getObjectsByBoard(String boardId, int position, int length,
![](https://i-blog.csdnimg.cn/blog_migrate/37c8bf68cdc3cc81759c34160776bc53.gif) String text) throws Exception ...{
Iterator iterator = null;
String queryString = " select "+pojoClass.getName().toLowerCase()+" from "+pojoClass.getName()+" as "+pojoClass.getName().toLowerCase()+" where "+pojoClass.getName().toLowerCase()+".boardId='" +
boardId + "' and "+pojoClass.getName().toLowerCase()+".title like '%" + text +
"%' order by "+pojoClass.getName().toLowerCase()+".id desc";
![](https://i-blog.csdnimg.cn/blog_migrate/6a9c071a08f1dae2d3e1c512000eef41.gif)
//创建查询
Query query = getHibernateTemplate().createQuery(getSession(), queryString);
//设置游标的起始点
query.setFirstResult(position);
//设置游标的长度
query.setMaxResults(length);
//记录生成
List list = query.list();
//把查询到的结果放入迭代器
iterator = list.iterator();
return iterator;
![](https://i-blog.csdnimg.cn/blog_migrate/6a9c071a08f1dae2d3e1c512000eef41.gif)
}
![](https://i-blog.csdnimg.cn/blog_migrate/6a9c071a08f1dae2d3e1c512000eef41.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/6a9c071a08f1dae2d3e1c512000eef41.gif)
/ ///
/以下部份带有审核功能 ///
/ ///
![](https://i-blog.csdnimg.cn/blog_migrate/6a9c071a08f1dae2d3e1c512000eef41.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/37c8bf68cdc3cc81759c34160776bc53.gif) /** *//**
* 取记录总数
* @return int
* @param int isAuditing
*/
![](https://i-blog.csdnimg.cn/blog_migrate/37c8bf68cdc3cc81759c34160776bc53.gif) public int getObjectsCount(int isAuditing) throws Exception ...{
int count = 0;
![](https://i-blog.csdnimg.cn/blog_migrate/6a9c071a08f1dae2d3e1c512000eef41.gif)
count = ((Integer) getHibernateTemplate().iterate(
"select count(*) from "+pojoClass.getName()+" as "+pojoClass.getName().toLowerCase()+" where "+pojoClass.getName().toLowerCase()+".isauditing=" +
isAuditing).next()).intValue();
return count;
}
![](https://i-blog.csdnimg.cn/blog_migrate/6a9c071a08f1dae2d3e1c512000eef41.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/6a9c071a08f1dae2d3e1c512000eef41.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/37c8bf68cdc3cc81759c34160776bc53.gif) /** *//**
* 取所有记录集合
* @return Iterator
* @param int position, int length,int isAuditing
*/
![](https://i-blog.csdnimg.cn/blog_migrate/37c8bf68cdc3cc81759c34160776bc53.gif) public Iterator getAllObjects(int isAuditing) throws Exception ...{
Iterator iterator = null;
String queryString =
" select "+pojoClass.getName().toLowerCase()+" from "+pojoClass.getName()+" as "+pojoClass.getName().toLowerCase()+" where "+pojoClass.getName().toLowerCase()+".isauditing=" + isAuditing +
" order by "+pojoClass.getName().toLowerCase()+".id desc";
Query query = getHibernateTemplate().createQuery(getSession(), queryString);
//记录生成
List list = query.list();
//把查询到的结果放入迭代器
iterator = list.iterator();
return iterator;
}
![](https://i-blog.csdnimg.cn/blog_migrate/6a9c071a08f1dae2d3e1c512000eef41.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/6a9c071a08f1dae2d3e1c512000eef41.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/37c8bf68cdc3cc81759c34160776bc53.gif) /** *//**
* 取记录集合
* @return Iterator
* @param int position, int length,int isAuditing
*/
public Iterator getObjects(int position, int length, int isAuditing) throws
![](https://i-blog.csdnimg.cn/blog_migrate/37c8bf68cdc3cc81759c34160776bc53.gif) Exception ...{
Iterator iterator = null;
String queryString =
" select "+pojoClass.getName().toLowerCase()+" from "+pojoClass.getName()+" as "+pojoClass.getName().toLowerCase()+" where "+pojoClass.getName().toLowerCase()+".isauditing=" + isAuditing +
" order by "+pojoClass.getName().toLowerCase()+".id desc";
![](https://i-blog.csdnimg.cn/blog_migrate/6a9c071a08f1dae2d3e1c512000eef41.gif)
Query query = getHibernateTemplate().createQuery(getSession(), queryString);
//设置游标的起始点
query.setFirstResult(position);
//设置游标的长度
query.setMaxResults(length);
//记录生成
List list = query.list();
//把查询到的结果放入迭代器
iterator = list.iterator();
![](https://i-blog.csdnimg.cn/blog_migrate/6a9c071a08f1dae2d3e1c512000eef41.gif)
return iterator;
}
![](https://i-blog.csdnimg.cn/blog_migrate/6a9c071a08f1dae2d3e1c512000eef41.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/6a9c071a08f1dae2d3e1c512000eef41.gif)
/ ///
/ 以下部份表中要有特定字段才能Õ吩诵Ð 有审核功能 个人和Æ笠禒 ///
/ ///
///
![](https://i-blog.csdnimg.cn/blog_migrate/6a9c071a08f1dae2d3e1c512000eef41.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/37c8bf68cdc3cc81759c34160776bc53.gif) /** *//**
* 取符合条件记录总数, [表中要有 isperson isAuditing 字段]
* @return int
* @param int isPerson,int isAuditing
*/
![](https://i-blog.csdnimg.cn/blog_migrate/6a9c071a08f1dae2d3e1c512000eef41.gif)
public int getObjectsCountByIsperson(int isPerson, int isAuditing) throws
![](https://i-blog.csdnimg.cn/blog_migrate/37c8bf68cdc3cc81759c34160776bc53.gif) Exception ...{
int count = 0;
![](https://i-blog.csdnimg.cn/blog_migrate/6a9c071a08f1dae2d3e1c512000eef41.gif)
count = ((Integer) getHibernateTemplate().iterate(
"select count(*) from "+pojoClass.getName()+" as "+pojoClass.getName().toLowerCase()+" where "+pojoClass.getName().toLowerCase()+".isperson =" + isPerson +
" and "+pojoClass.getName().toLowerCase()+".isauditing=" + isAuditing).next()).intValue();
![](https://i-blog.csdnimg.cn/blog_migrate/6a9c071a08f1dae2d3e1c512000eef41.gif)
return count;
}
![](https://i-blog.csdnimg.cn/blog_migrate/6a9c071a08f1dae2d3e1c512000eef41.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/6a9c071a08f1dae2d3e1c512000eef41.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/37c8bf68cdc3cc81759c34160776bc53.gif) /** *//**
* 取所有符合条件记录集合, 模糊查询条件.[表中要有 isperson isAuditing 字段]
* @return Iterator
* @param int isPerson,int isAuditing
*/
![](https://i-blog.csdnimg.cn/blog_migrate/6a9c071a08f1dae2d3e1c512000eef41.gif)
public Iterator getAllObjectsByIsperson(int isPerson, int isAuditing) throws
![](https://i-blog.csdnimg.cn/blog_migrate/37c8bf68cdc3cc81759c34160776bc53.gif) Exception ...{
Iterator iterator = null;
String queryString = " select "+pojoClass.getName().toLowerCase()+" from "+pojoClass.getName()+" as "+pojoClass.getName().toLowerCase()+" where "+pojoClass.getName().toLowerCase()+".isperson =" +
isPerson + " and "+pojoClass.getName().toLowerCase()+".isauditing=" + isAuditing +
" order by "+pojoClass.getName().toLowerCase()+".id desc";
![](https://i-blog.csdnimg.cn/blog_migrate/6a9c071a08f1dae2d3e1c512000eef41.gif)
Query query = getHibernateTemplate().createQuery(getSession(), queryString);
//记录生成
List list = query.list();
//把查询到的结果放入迭代器
iterator = list.iterator();
![](https://i-blog.csdnimg.cn/blog_migrate/6a9c071a08f1dae2d3e1c512000eef41.gif)
return iterator;
}
![](https://i-blog.csdnimg.cn/blog_migrate/6a9c071a08f1dae2d3e1c512000eef41.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/6a9c071a08f1dae2d3e1c512000eef41.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/37c8bf68cdc3cc81759c34160776bc53.gif) /** *//**
* 取符合条件记录集合, 模糊查询条件.[表中要有 isperson isAuditing 字段]
* @return Iterator
* @param int isPerson,int position, int length,int isAuditing
*/
![](https://i-blog.csdnimg.cn/blog_migrate/6a9c071a08f1dae2d3e1c512000eef41.gif)
public Iterator getObjectsByIsperson(int isPerson, int position, int length,
![](https://i-blog.csdnimg.cn/blog_migrate/37c8bf68cdc3cc81759c34160776bc53.gif) int isAuditing) throws Exception ...{
Iterator iterator = null;
String queryString = " select "+pojoClass.getName().toLowerCase()+" from "+pojoClass.getName()+" as "+pojoClass.getName().toLowerCase()+" where "+pojoClass.getName().toLowerCase()+".isperson =" +
isPerson + " and "+pojoClass.getName().toLowerCase()+".isauditing=" + isAuditing +
" order by "+pojoClass.getName().toLowerCase()+".id desc";
![](https://i-blog.csdnimg.cn/blog_migrate/6a9c071a08f1dae2d3e1c512000eef41.gif)
Query query = getHibernateTemplate().createQuery(getSession(), queryString);
//设置游标的起始点
query.setFirstResult(position);
//设置游标的长度
query.setMaxResults(length);
//记录生成
List list = query.list();
//把查询到的结果放入迭代器
iterator = list.iterator();
![](https://i-blog.csdnimg.cn/blog_migrate/6a9c071a08f1dae2d3e1c512000eef41.gif)
return iterator;
![](https://i-blog.csdnimg.cn/blog_migrate/6a9c071a08f1dae2d3e1c512000eef41.gif)
}
![](https://i-blog.csdnimg.cn/blog_migrate/6a9c071a08f1dae2d3e1c512000eef41.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/6a9c071a08f1dae2d3e1c512000eef41.gif)
/ ///
/ 要有特定字段才能Õ吩诵袪 有审核功能 查询部份 ///
/ ///
///
![](https://i-blog.csdnimg.cn/blog_migrate/37c8bf68cdc3cc81759c34160776bc53.gif) /** *//**
* 取符合条件记录总数, 模糊查询条件.[表中要有 title 字段]
* @return int
* @param String text,int isAuditing
*/
![](https://i-blog.csdnimg.cn/blog_migrate/37c8bf68cdc3cc81759c34160776bc53.gif) public int getObjectsCount(String text, int isAuditing) throws Exception ...{
int count = 0;
![](https://i-blog.csdnimg.cn/blog_migrate/6a9c071a08f1dae2d3e1c512000eef41.gif)
count = ((Integer) getHibernateTemplate().iterate(
"select count(*) from "+pojoClass.getName()+" as "+pojoClass.getName().toLowerCase()+" where "+pojoClass.getName().toLowerCase()+".isauditing=" +
isAuditing + " and "+pojoClass.getName().toLowerCase()+".title like '%" + text + "%'").next()).
intValue();
![](https://i-blog.csdnimg.cn/blog_migrate/6a9c071a08f1dae2d3e1c512000eef41.gif)
return count;
}
![](https://i-blog.csdnimg.cn/blog_migrate/6a9c071a08f1dae2d3e1c512000eef41.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/6a9c071a08f1dae2d3e1c512000eef41.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/37c8bf68cdc3cc81759c34160776bc53.gif) /** *//**
* 取所有符合条件记录集合, 模糊查询条件.[表中要有 title 字段]
* @return Iterator
* @param String text,int isAuditing
*/
![](https://i-blog.csdnimg.cn/blog_migrate/6a9c071a08f1dae2d3e1c512000eef41.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/37c8bf68cdc3cc81759c34160776bc53.gif) public Iterator getAllObjects(String text, int isAuditing) throws Exception ...{
Iterator iterator = null;
String queryString =
" select "+pojoClass.getName().toLowerCase()+" from "+pojoClass.getName()+" as "+pojoClass.getName().toLowerCase()+" where "+pojoClass.getName().toLowerCase()+".isauditing=" + isAuditing +
" and "+pojoClass.getName().toLowerCase()+".title like '%" + text + "%' order by "+pojoClass.getName().toLowerCase()+".id desc";
![](https://i-blog.csdnimg.cn/blog_migrate/6a9c071a08f1dae2d3e1c512000eef41.gif)
Query query = getHibernateTemplate().createQuery(getSession(), queryString);
//记录生成
List list = query.list();
//把查询到的结果放入迭代器
iterator = list.iterator();
![](https://i-blog.csdnimg.cn/blog_migrate/6a9c071a08f1dae2d3e1c512000eef41.gif)
return iterator;
}
![](https://i-blog.csdnimg.cn/blog_migrate/6a9c071a08f1dae2d3e1c512000eef41.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/6a9c071a08f1dae2d3e1c512000eef41.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/37c8bf68cdc3cc81759c34160776bc53.gif) /** *//**
* 取符合条件记录集合, 模糊查询条件.[表中要有 title 字段]
* @return Iterator
* @param String text,int position, int length,int isAuditing
*/
public Iterator getObjects(String text, int position, int length,
![](https://i-blog.csdnimg.cn/blog_migrate/37c8bf68cdc3cc81759c34160776bc53.gif) int isAuditing) throws Exception ...{
Iterator iterator = null;
String queryString =
" select "+pojoClass.getName().toLowerCase()+" from "+pojoClass.getName()+" as "+pojoClass.getName().toLowerCase()+" where "+pojoClass.getName().toLowerCase()+".isauditing=" + isAuditing +
" and "+pojoClass.getName().toLowerCase()+".title like '%" + text + "%' order by "+pojoClass.getName().toLowerCase()+".id desc";
![](https://i-blog.csdnimg.cn/blog_migrate/6a9c071a08f1dae2d3e1c512000eef41.gif)
//创建查询
Query query = getHibernateTemplate().createQuery(getSession(), queryString);
//设置游标的起始点
query.setFirstResult(position);
//设置游标的长度
query.setMaxResults(length);
//记录生成
List list = query.list();
//把查询到的结果放入迭代器
iterator = list.iterator();
![](https://i-blog.csdnimg.cn/blog_migrate/6a9c071a08f1dae2d3e1c512000eef41.gif)
return iterator;
}
![](https://i-blog.csdnimg.cn/blog_migrate/6a9c071a08f1dae2d3e1c512000eef41.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/6a9c071a08f1dae2d3e1c512000eef41.gif)
/ ///
/ 要有特定字段才能Õ吩诵袪 有审核功能 注册相关 ///
/ ///
![](https://i-blog.csdnimg.cn/blog_migrate/6a9c071a08f1dae2d3e1c512000eef41.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/37c8bf68cdc3cc81759c34160776bc53.gif) /** *//**
* 取符合条件记录总数.[ 表中要有 registername isauditing字段]
* @return int
* @param String text,int isAuditing
*/
public int getObjectsCountByRegisterName(String registerName, int isAuditing) throws
![](https://i-blog.csdnimg.cn/blog_migrate/37c8bf68cdc3cc81759c34160776bc53.gif) Exception ...{
int count = 0;
![](https://i-blog.csdnimg.cn/blog_migrate/6a9c071a08f1dae2d3e1c512000eef41.gif)
count = ((Integer) getHibernateTemplate().iterate(
"select count(*) from "+pojoClass.getName()+" as "+pojoClass.getName().toLowerCase()+" where "+pojoClass.getName().toLowerCase()+".isauditing=" +
isAuditing + " and "+pojoClass.getName().toLowerCase()+".registername = '" + registerName + "'").next()).
intValue();
![](https://i-blog.csdnimg.cn/blog_migrate/6a9c071a08f1dae2d3e1c512000eef41.gif)
return count;
}
![](https://i-blog.csdnimg.cn/blog_migrate/6a9c071a08f1dae2d3e1c512000eef41.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/6a9c071a08f1dae2d3e1c512000eef41.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/37c8bf68cdc3cc81759c34160776bc53.gif) /** *//**
* 通过注册名取得一条记录,如有多条,只取第一条.[表中要有 registername isauditing字段]
* @param registername String,int isAuditing
* @return Object
*/
public Object getObjectByRegisterName(String registerName, int isAuditing) throws
![](https://i-blog.csdnimg.cn/blog_migrate/37c8bf68cdc3cc81759c34160776bc53.gif) Exception ...{
Iterator iterator = null;
Object object = null;
![](https://i-blog.csdnimg.cn/blog_migrate/6a9c071a08f1dae2d3e1c512000eef41.gif)
String queryString =
" select "+pojoClass.getName().toLowerCase()+" from "+pojoClass.getName()+" as "+pojoClass.getName().toLowerCase()+" where "+pojoClass.getName().toLowerCase()+".isauditing=" + isAuditing +
" and "+pojoClass.getName().toLowerCase()+".registername='" + registerName + "' order by "+pojoClass.getName().toLowerCase()+".id desc";
![](https://i-blog.csdnimg.cn/blog_migrate/6a9c071a08f1dae2d3e1c512000eef41.gif)
Query query = getHibernateTemplate().createQuery(getSession(), queryString);
//记录生成
List list = query.list();
//把查询到的结果放入迭代器
iterator = list.iterator();
![](https://i-blog.csdnimg.cn/blog_migrate/37c8bf68cdc3cc81759c34160776bc53.gif) if (iterator.hasNext()) ...{
object = (Object) iterator.next();
}
![](https://i-blog.csdnimg.cn/blog_migrate/6a9c071a08f1dae2d3e1c512000eef41.gif)
return object;
}
![](https://i-blog.csdnimg.cn/blog_migrate/6a9c071a08f1dae2d3e1c512000eef41.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/6a9c071a08f1dae2d3e1c512000eef41.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/37c8bf68cdc3cc81759c34160776bc53.gif) /** *//**
* 通过注册名取得所有记录集合.[表中要有 registername isauditing字段]
* @param registername String,int isAuditing
* @return Iterator
*/
public Iterator getAllObjectsByRegisterName(String registerName, int isAuditing) throws
![](https://i-blog.csdnimg.cn/blog_migrate/37c8bf68cdc3cc81759c34160776bc53.gif) Exception ...{
Iterator iterator = null;
![](https://i-blog.csdnimg.cn/blog_migrate/6a9c071a08f1dae2d3e1c512000eef41.gif)
String queryString =
" select "+pojoClass.getName().toLowerCase()+" from "+pojoClass.getName()+" as "+pojoClass.getName().toLowerCase()+" where "+pojoClass.getName().toLowerCase()+".isauditing=" + isAuditing +
" and "+pojoClass.getName().toLowerCase()+".registername='" + registerName + "' order by "+pojoClass.getName().toLowerCase()+".id desc";
![](https://i-blog.csdnimg.cn/blog_migrate/6a9c071a08f1dae2d3e1c512000eef41.gif)
Query query = getHibernateTemplate().createQuery(getSession(), queryString);
//记录生成
List list = query.list();
//把查询到的结果放入迭代器
iterator = list.iterator();
![](https://i-blog.csdnimg.cn/blog_migrate/6a9c071a08f1dae2d3e1c512000eef41.gif)
return iterator;
}
![](https://i-blog.csdnimg.cn/blog_migrate/6a9c071a08f1dae2d3e1c512000eef41.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/6a9c071a08f1dae2d3e1c512000eef41.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/37c8bf68cdc3cc81759c34160776bc53.gif) /** *//**
* 通过注册名取得记录列表.[表中要有 registername isauditing字段]
* @param registername String,int isAuditing
* @return Iterator
*/
public Iterator getObjectsByRegisterName(String registerName, int position,
int length, int isAuditing) throws
![](https://i-blog.csdnimg.cn/blog_migrate/37c8bf68cdc3cc81759c34160776bc53.gif) Exception ...{
Iterator iterator = null;
String queryString =
" select "+pojoClass.getName().toLowerCase()+" from "+pojoClass.getName()+" as "+pojoClass.getName().toLowerCase()+" where "+pojoClass.getName().toLowerCase()+".isauditing=" + isAuditing +
" and "+pojoClass.getName().toLowerCase()+".registername='" + registerName + "' order by "+pojoClass.getName().toLowerCase()+".id desc";
![](https://i-blog.csdnimg.cn/blog_migrate/6a9c071a08f1dae2d3e1c512000eef41.gif)
//创建查询
Query query = getHibernateTemplate().createQuery(getSession(), queryString);
//设置游标的起始点
query.setFirstResult(position);
//设置游标的长度
query.setMaxResults(length);
//记录生成
List list = query.list();
//把查询到的结果放入迭代器
iterator = list.iterator();
![](https://i-blog.csdnimg.cn/blog_migrate/6a9c071a08f1dae2d3e1c512000eef41.gif)
return iterator;
}
![](https://i-blog.csdnimg.cn/blog_migrate/6a9c071a08f1dae2d3e1c512000eef41.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/6a9c071a08f1dae2d3e1c512000eef41.gif)
/ ///
/ 要有特定字段才能Õ吩诵袪 有审核功能 树型版块 ///
/ ///
![](https://i-blog.csdnimg.cn/blog_migrate/6a9c071a08f1dae2d3e1c512000eef41.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/37c8bf68cdc3cc81759c34160776bc53.gif) /** *//**
* 取记录总数.[ 表中要有 board_id isauditing字段]
* @return int
* @param String boardId,int isAuditing
*/
public int getObjectsCountByBoard(String boardId, int isAuditing) throws
![](https://i-blog.csdnimg.cn/blog_migrate/37c8bf68cdc3cc81759c34160776bc53.gif) Exception ...{
int count = 0;
![](https://i-blog.csdnimg.cn/blog_migrate/6a9c071a08f1dae2d3e1c512000eef41.gif)
count = ((Integer) getHibernateTemplate().iterate(
"select count(*) from "+pojoClass.getName()+" as "+pojoClass.getName().toLowerCase()+" where "+pojoClass.getName().toLowerCase()+".isauditing=" +
isAuditing + " and "+pojoClass.getName().toLowerCase()+".boardId = '" + boardId + "'").next()).intValue();
![](https://i-blog.csdnimg.cn/blog_migrate/6a9c071a08f1dae2d3e1c512000eef41.gif)
return count;
}
![](https://i-blog.csdnimg.cn/blog_migrate/6a9c071a08f1dae2d3e1c512000eef41.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/6a9c071a08f1dae2d3e1c512000eef41.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/37c8bf68cdc3cc81759c34160776bc53.gif) /** *//**
* 通过版块名取得所有记录集合.[表中要有 board_id isauditing字段]
* @param BoardId String,int isAuditing
* @return Iterator
*/
public Iterator getAllObjectsByBoard(String boardId, int isAuditing) throws
![](https://i-blog.csdnimg.cn/blog_migrate/37c8bf68cdc3cc81759c34160776bc53.gif) Exception ...{
Iterator iterator = null;
![](https://i-blog.csdnimg.cn/blog_migrate/6a9c071a08f1dae2d3e1c512000eef41.gif)
String queryString =
" select "+pojoClass.getName().toLowerCase()+" from "+pojoClass.getName()+" as "+pojoClass.getName().toLowerCase()+" where "+pojoClass.getName().toLowerCase()+".isauditing=" + isAuditing +
" and "+pojoClass.getName().toLowerCase()+".boardId='" + boardId + "' order by "+pojoClass.getName().toLowerCase()+".id desc";
![](https://i-blog.csdnimg.cn/blog_migrate/6a9c071a08f1dae2d3e1c512000eef41.gif)
Query query = getHibernateTemplate().createQuery(getSession(), queryString);
//记录生成
List list = query.list();
//把查询到的结果放入迭代器
iterator = list.iterator();
return iterator;
}
![](https://i-blog.csdnimg.cn/blog_migrate/6a9c071a08f1dae2d3e1c512000eef41.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/6a9c071a08f1dae2d3e1c512000eef41.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/37c8bf68cdc3cc81759c34160776bc53.gif) /** *//**
* 通过版块名取得记录列表.[表中要有 board_id isauditing字段]
* @param BoardId String,int isAuditing
* @return Iterator
*/
public Iterator getObjectsByBoard(String boardId, int position, int length,
![](https://i-blog.csdnimg.cn/blog_migrate/37c8bf68cdc3cc81759c34160776bc53.gif) int isAuditing) throws Exception ...{
Iterator iterator = null;
String queryString =
" select "+pojoClass.getName().toLowerCase()+" from "+pojoClass.getName()+" as "+pojoClass.getName().toLowerCase()+" where "+pojoClass.getName().toLowerCase()+".isauditing=" + isAuditing +
" and "+pojoClass.getName().toLowerCase()+".boardId='" + boardId + "' order by "+pojoClass.getName().toLowerCase()+".id desc";
![](https://i-blog.csdnimg.cn/blog_migrate/6a9c071a08f1dae2d3e1c512000eef41.gif)
//创建查询
Query query = getHibernateTemplate().createQuery(getSession(), queryString);
//设置游标的起始点
query.setFirstResult(position);
//设置游标的长度
query.setMaxResults(length);
//记录生成
List list = query.list();
//把查询到的结果放入迭代器
iterator = list.iterator();
![](https://i-blog.csdnimg.cn/blog_migrate/6a9c071a08f1dae2d3e1c512000eef41.gif)
return iterator;
![](https://i-blog.csdnimg.cn/blog_migrate/6a9c071a08f1dae2d3e1c512000eef41.gif)
}
![](https://i-blog.csdnimg.cn/blog_migrate/6a9c071a08f1dae2d3e1c512000eef41.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/6a9c071a08f1dae2d3e1c512000eef41.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/37c8bf68cdc3cc81759c34160776bc53.gif) /** *//**
* 取符合条件记录总数.[ 表中要有 board_id isauditing字段,title] 模糊查询title
* @return int
* @param String boardId ,String text,int isAuditing
*/
public int getObjectsCountByBoard(String boardId, String text, int isAuditing) throws
![](https://i-blog.csdnimg.cn/blog_migrate/37c8bf68cdc3cc81759c34160776bc53.gif) Exception ...{
int count = 0;
![](https://i-blog.csdnimg.cn/blog_migrate/6a9c071a08f1dae2d3e1c512000eef41.gif)
count = ((Integer) getHibernateTemplate().iterate(
"select count(*) from "+pojoClass.getName()+" as "+pojoClass.getName().toLowerCase()+" where "+pojoClass.getName().toLowerCase()+".isauditing=" +
isAuditing + " and "+pojoClass.getName().toLowerCase()+".boardId='" + boardId +
"' and "+pojoClass.getName().toLowerCase()+".title like '%" +
text + "%'").next()).intValue();
![](https://i-blog.csdnimg.cn/blog_migrate/6a9c071a08f1dae2d3e1c512000eef41.gif)
return count;
![](https://i-blog.csdnimg.cn/blog_migrate/6a9c071a08f1dae2d3e1c512000eef41.gif)
}
![](https://i-blog.csdnimg.cn/blog_migrate/6a9c071a08f1dae2d3e1c512000eef41.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/6a9c071a08f1dae2d3e1c512000eef41.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/37c8bf68cdc3cc81759c34160776bc53.gif) /** *//**
* 通过版块名取得记录列表.[表中要有 board_id字段 isauditing] 模糊查询title
* @param String boardId,int position, int length,int isAuditing
* @return Iterator
*/
public Iterator getObjectsByBoard(String boardId, int position, int length,
![](https://i-blog.csdnimg.cn/blog_migrate/37c8bf68cdc3cc81759c34160776bc53.gif) String text, int isAuditing) throws Exception ...{
Iterator iterator = null;
String queryString =
" select "+pojoClass.getName().toLowerCase()+" from "+pojoClass.getName()+" as "+pojoClass.getName().toLowerCase()+" where "+pojoClass.getName().toLowerCase()+".isauditing=" + isAuditing +
" and "+pojoClass.getName().toLowerCase()+".boardId='" + boardId + "' and "+pojoClass.getName().toLowerCase()+".title like '%" + text +
"%' order by "+pojoClass.getName().toLowerCase()+".id desc";
![](https://i-blog.csdnimg.cn/blog_migrate/6a9c071a08f1dae2d3e1c512000eef41.gif)
//创建查询
Query query = getHibernateTemplate().createQuery(getSession(), queryString);
//设置游标的起始点
query.setFirstResult(position);
//设置游标的长度
query.setMaxResults(length);
//记录生成
List list = query.list();
//把查询到的结果放入迭代器
iterator = list.iterator();
![](https://i-blog.csdnimg.cn/blog_migrate/6a9c071a08f1dae2d3e1c512000eef41.gif)
return iterator;
![](https://i-blog.csdnimg.cn/blog_migrate/6a9c071a08f1dae2d3e1c512000eef41.gif)
}
![](https://i-blog.csdnimg.cn/blog_migrate/6a9c071a08f1dae2d3e1c512000eef41.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/37c8bf68cdc3cc81759c34160776bc53.gif) /** *//**
* 设置DAO操作的POJO类
* @param pojoObject Object
*/
![](https://i-blog.csdnimg.cn/blog_migrate/37c8bf68cdc3cc81759c34160776bc53.gif) public void init(Class pojoClass) ...{
this.pojoClass = pojoClass;
}
![](https://i-blog.csdnimg.cn/blog_migrate/6a9c071a08f1dae2d3e1c512000eef41.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/6a9c071a08f1dae2d3e1c512000eef41.gif)
}
![](https://i-blog.csdnimg.cn/blog_migrate/6810355c2f78c12e91b7997a8e8c583a.gif)
|