/**
 * 根据最大页数、开始记录数返回对应记录集
 * @param pageSize 最大页数
 * @param page     开始记录数
 * @return
 * @throws Exception
 */
public List getRSofPage(int pageSize,int page) throws Exception {
List retList = new ArrayList();
Session sess = null;
try {
sess = HibernateUtil.currentSession();
Transaction tx = sess.beginTransaction();
Query q = sess
.createQuery("from Channel where ParentId is not 0 order by ParentId ,ChannelId ");
q.setMaxResults( pageSize );
q.setFirstResult( (page - 1) * pageSize );
retList = q.list();
tx.commit();
//log
logger.info("(@@@@@@@@@@@ 根据最大页数、开始记录数返回对应记录集执行正常 @@@@@@@@@@@)");
} catch (HibernateException he) {
//log
logger.error("(@@@@@@@@@@@ 根据最大页数、开始记录数返回对应记录集执行异常 @@@@@@@@@@@)", he);
new org.hibernate.HibernateException("getRSofPage():"+listErrors);
} finally {
try {
    HibernateUtil.closeSession();
} catch (HibernateException he) {
new org.hibernate.HibernateException(
"HibernateUtilServlet.closeSession()");
}
}
return retList;
}

解决方案 »

  1.   

    hibernate 里面就有分页的方法都已经封装好了
      

  2.   

    display标签是一个相当强大的标签
    <% String uri="showLog.do"; %>
    <display:table name="rsList" width="100%" requestURI="<%=uri%>"   pagesize="<%=((SessionContainer)session.getAttribute(Constant.SESSION_CONTAINER_KEY)).getPageSize()%>" uid="item" cellspacing='1' cellpadding='0' >
    <display:caption style="text-align:left;" >日志列表:</display:caption>
    <display:column   property="log_date" title="时间"   width="20%"  align="center"  /> 
    <display:column   property="log_name" title="操作人员"   width="20%"  align="center"  /> 
    <display:column    property="log_cont" title="操作内容"   width="20%"  align="center"  /> 
    <display:column    property="log_part" title="所操作内容所属模块"   width="20%"  align="center"  /> </display:table>
      

  3.   

    display标签是一个相当强大的标签 
    <%   String   uri= "showLog.do "; %> 
    <display:table   name= "rsList "   width= "100% "   requestURI= " <%=uri%> "       pagesize= " <%=((SessionContainer)session.getAttribute(Constant.SESSION_CONTAINER_KEY)).getPageSize()%> "   uid= "item "   cellspacing= '1 '   cellpadding= '0 '   > 
    <display:caption   style= "text-align:left; "   > 日志列表: </display:caption> 
    <display:column       property= "log_date "   title= "时间 "       width= "20% "     align= "center "     />   
    <display:column       property= "log_name "   title= "操作人员 "       width= "20% "     align= "center "     />   
    <display:column         property= "log_cont "   title= "操作内容 "       width= "20% "     align= "center "     />   
    <display:column         property= "log_part "   title= "所操作内容所属模块 "       width= "20% "     align= "center "     />   </display:table> 
    我听别人说不能用无敌百分号和表达式
    应该用EL和JSTL