如果能帮上您的忙,就帮我点击下面的网站,帮我提高一下点击率
// 分页处理
public List findByPage(final int first, final int pageSize,final String fieldname,final String records,final String lb)
{
try {
List result = (List)getHibernateTemplate().execute(
new HibernateCallback()
{
public Object doInHibernate(Session sess)throws HibernateException
{
List tmp = sess.createQuery("from HgCwzd m where "+fieldname+" like :records and bz1 like :sqlb order by id desc")
.setString("records","%"+records+"%")
.setString("sqlb", "%"+lb+"%")
.setFirstResult(first)
.setMaxResults(pageSize)
.list();
return tmp;
}
});
return result;
} catch (RuntimeException re) {
log.error("find by property name failed", re);
throw re;
}
}
public int getPages(int pageSize,String fieldname,String records,String sqlb)
{//获取总页数
try {
String args[] = {"%"+records+"%","%"+sqlb+"%"};
List list = getHibernateTemplate().find("SELECT count(id) from HgCwzd where "+fieldname+" like ? and bz1 like ?",args);
int j = 0;
j = ((Integer)list.iterator().next()).intValue();
int i = 0;
if(j%pageSize==0) i = j/pageSize;
else i = j/pageSize+1;
return i;
} catch (RuntimeException re) {
log.error("find by property name failed", re);
throw re;
}
}
public int getRows(String fieldname,String records,String sqlb)
{//获取总行数
try {
String args[] = {"%"+records+"%","%"+sqlb+"%"};
List list = getHibernateTemplate().find("SELECT count(id) from HgCwzd where "+fieldname+" like ? and bz1 like ? ",args);
return ((Integer)list.iterator().next()).intValue();
} catch (RuntimeException re) {
log.error("find by property name failed", re);
throw re;
}
}