package com.bjsxt.oa.manager.impl; import java.util.List; import org.hibernate.Query; import org.springframework.orm.hibernate3.support.HibernateDaoSupport; import com.bjsxt.oa.PagerModel; import com.bjsxt.oa.SystemContext; import com.bjsxt.oa.manager.SystemException; public class AbstractManager extends HibernateDaoSupport { public PagerModel searchPaginated(String hql){ return searchPaginated(hql, null); } public PagerModel searchPaginated(String hql,Object param){ return searchPaginated(hql, new Object[]{param}); } public PagerModel searchPaginated(String hql,Object[] params){ return searchPaginated(hql, params,SystemContext.getOffset(), SystemContext.getPagesize()); } public PagerModel searchPaginated(String hql,int offset,int pagesize){ return searchPaginated(hql,null, offset, pagesize); } public PagerModel searchPaginated(String hql,Object param,int offset,int pagesize){ return searchPaginated(hql, new Object[]{param}, offset, pagesize); } public PagerModel searchPaginated(String hql,Object[] params,int offset,int pagesize){ //获取记录总数 String countHql = getCountQuery(hql); Query query = getSession().createQuery(countHql); if(params != null && params.length > 0){ for(int i=0; i<params.length; i++){ query.setParameter(i, params[i]); } } int total = ((Long)query.uniqueResult()).intValue(); //获取结果集 query = getSession().createQuery(hql); if(params != null && params.length > 0){ for(int i=0; i<params.length; i++){ query.setParameter(i, params[i]); } } query.setFirstResult(offset); query.setMaxResults(pagesize); List datas = query.list(); //返回PagerModel PagerModel pm = new PagerModel(); pm.setDatas(datas); pm.setTotal(total); return pm; } /** * 根据HQL语句,获得查询总记录数的HQL语句 * 如: * select ... from Organization o where o.parent is null * 经过转换,可以得到: * select count(*) from Organziation o where o.parent is null * @param hql * @return */ private String getCountQuery(String hql){ int index = hql.indexOf("from"); if(index != -1){ return "select count(*) " + hql.substring(index); } throw new SystemException("无效的HQL查询语句【"+hql+"】"); } }

cx123123 LV7
2022年5月18日
and123456 LV11
2022年2月7日
luk7153 LV3
2021年9月24日
huaua7676 LV30
2021年7月25日
17852310375 LV3
2021年4月27日
ayanamirei LV3
2021年4月21日
shiyujir LV7
2021年4月7日
zh17826038126 LV2
2021年1月4日
过去的事刚擦手感不错 LV2
2020年10月13日
ddqddqddq LV14
2020年9月5日

微信网友_7398626323435520 LV2
2月25日
krispeng LV14
2024年8月12日
yunsgui LV1
2024年6月25日
vluobo LV1
2024年3月19日
Gin19960217 LV4
2024年3月5日
1134116035
2024年2月21日
暂无贡献等级
氟西汀来救你 LV2
2024年1月9日
WBelong LV8
2023年12月25日
dazhuang123
2023年10月7日
暂无贡献等级
fesfefe LV13
2023年9月26日