struts1.3+hibernate3.2+spring2.5怎么实现分页显示呢,还请各位帮忙! 我最多只有94分了,哪位大哥给解决一下,全给一个人! 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 hibernate不是有分页的函数?Query q = session.createQuery("from Person as p"); q.setFirstResult(20000); q.setMaxResults(100); List l = q.list();其中 setFirstResult()函数设置的是从第几笔记录开始取, q.setMaxResults(100)函数设置的是取多少笔记录。 用hibnate做分页的话只相对于小型项目,如果做大型项目建议还是用jsp做google搜一下 很多的! 2楼给出了最核心的代码。楼主还是google一下吧 DAO里面的某一个方法: public List findMessageByTechId(final Integer id,final Page page,final Integer rid){ return (List) this.getHibernateTemplate().execute( new HibernateCallback() { public Object doInHibernate(Session session) throws HibernateException, SQLException { Query query = session.createQuery( "from Message where techId=:id and recopyId=:rid").setInteger( "id", id).setInteger("rid", rid); if(page!=null){ query.setFirstResult(page.getStartnum()); query.setMaxResults(page.getPagesize()); } if (query.list().iterator().hasNext()) return query.list(); else return null; } }); } 用pager-taglib 做分页显示挺不多 action里面控制,接收service并跳转// 从页面获得偏移量 Integer pagesize=30; session.setAttribute("pagesize", pagesize); // 从页面获得偏移量 String offset = request.getParameter("pager.offset"); if (offset == null) { // 第一次查询,需要查出记录总数 String count = ""; count = this.technologyStoreService .findTechByisAuditSharePageNum(2,searchScope.getGrade(),searchScope.getDeptid()).toString(); // 只需要下传页面总记录数,每页记录数即可。 session.setAttribute("resultSize", count); } if (offset == null || offset.equals("")) { offset = "0"; } int intoffset = 0; if (offset != null && !offset.equals("")) { intoffset = Integer.parseInt(offset); } final Page page = new Page(intoffset, pagesize); session.setAttribute("pagesize", pagesize); // 查询处索要的list List tmp = this.technologyStoreService .findTechByisAuditSharePage(2, page,searchScope.getGrade(),searchScope.getDeptid()); session.setAttribute("slist", tmp); if (tmp != null && tmp.size() > 0) { LinkedList<TechnologyStore> sortList = new LinkedList<TechnologyStore>(tmp); session.setAttribute("morelist", sortList); } String method = "showmodel1"; session.setAttribute("method", method); ActionForward forward = new ActionForward("/technologyStore/indexCom.jsp"); return forward; jsp页面里用到标签 <pg:pager items="${sessionScope.resultSizeDetail }" maxPageItems="${requestScope.pagesizeDetail}" maxIndexPages="<%=10%>" isOffset="<%=true%>" url="/lhkjywgl/technologyStore/addTechnologyStore.do" export="offset,currentPageNumber=pageNumber" scope="request"> <pg:param name="operate" value="detail"></pg:param> <pg:param name="technologyStore1" value="${technologyStore1}"></pg:param> <pg:param name="recopyId" value="${recopyId}"></pg:param> <pg:param name="recopyIdd" value="${recopyIdd}"></pg:param> <pg:param name="id" value="${id}"></pg:param> <pg:param name="op" value="op"></pg:param> <pg:param name="niming" value="0"></pg:param> <jsp:include page="/plugins/paging/jsp/altavista.jsp" flush="true" /> <!-- 从page对象中取得属性值firstItem , lastIterm --> <pg:page export="firstItem, lastItem"> <font color="red">本页 <strong><%=firstItem%> </strong> -- <strong> <%=lastItem%> </strong>条 <strong>/</strong> 总记录数 <strong><bean:write name="resultSizeDetail" /> </strong>条 </font> </pg:page> </pg:pager> 附件的数据库设计 .net DAO 一个关于JS的问题!! ResultSet定义变量的类型怎么转化为int型?请指教 关于在Servlet里调用批处理(.bat文件)运行Ant的问题(各位有没有试过呢?),请大家讨论下,正解必给分 hashtable怎么可以倒序遍历? JSP学习的问题请大家帮忙!! 属性的判断及在jsp页面上的显示问题??? 巨急:resin运行平台中如何配置系统的环境变量?? 如何准确获取客户端的IP地址 帮帮忙 啊 文件下载
Query q = session.createQuery("from Person as p");
q.setFirstResult(20000);
q.setMaxResults(100);
List l = q.list();其中 setFirstResult()函数设置的是从第几笔记录开始取,
q.setMaxResults(100)函数设置的是取多少笔记录。
google搜一下 很多的!
public List findMessageByTechId(final Integer id,final Page page,final Integer rid){
return (List) this.getHibernateTemplate().execute(
new HibernateCallback() {
public Object doInHibernate(Session session)
throws HibernateException, SQLException {
Query query = session.createQuery(
"from Message where techId=:id and recopyId=:rid").setInteger(
"id", id).setInteger("rid", rid);
if(page!=null){
query.setFirstResult(page.getStartnum());
query.setMaxResults(page.getPagesize());
}
if (query.list().iterator().hasNext())
return query.list();
else
return null;
}
});
}
用pager-taglib 做分页显示挺不多
action里面控制,接收service并跳转// 从页面获得偏移量
Integer pagesize=30;
session.setAttribute("pagesize", pagesize);
// 从页面获得偏移量
String offset = request.getParameter("pager.offset"); if (offset == null) {
// 第一次查询,需要查出记录总数
String count = "";
count = this.technologyStoreService
.findTechByisAuditSharePageNum(2,searchScope.getGrade(),searchScope.getDeptid()).toString();
// 只需要下传页面总记录数,每页记录数即可。
session.setAttribute("resultSize", count);
} if (offset == null || offset.equals("")) {
offset = "0";
}
int intoffset = 0;
if (offset != null && !offset.equals("")) {
intoffset = Integer.parseInt(offset);
} final Page page = new Page(intoffset, pagesize);
session.setAttribute("pagesize", pagesize);
// 查询处索要的list
List tmp = this.technologyStoreService
.findTechByisAuditSharePage(2, page,searchScope.getGrade(),searchScope.getDeptid());
session.setAttribute("slist", tmp);
if (tmp != null && tmp.size() > 0) {
LinkedList<TechnologyStore> sortList = new LinkedList<TechnologyStore>(tmp);
session.setAttribute("morelist", sortList);
}
String method = "showmodel1";
session.setAttribute("method", method);
ActionForward forward = new ActionForward("/technologyStore/indexCom.jsp");
return forward;
<pg:pager items="${sessionScope.resultSizeDetail }"
maxPageItems="${requestScope.pagesizeDetail}"
maxIndexPages="<%=10%>" isOffset="<%=true%>"
url="/lhkjywgl/technologyStore/addTechnologyStore.do"
export="offset,currentPageNumber=pageNumber"
scope="request">
<pg:param name="operate" value="detail"></pg:param>
<pg:param name="technologyStore1"
value="${technologyStore1}"></pg:param>
<pg:param name="recopyId" value="${recopyId}"></pg:param>
<pg:param name="recopyIdd" value="${recopyIdd}"></pg:param>
<pg:param name="id" value="${id}"></pg:param>
<pg:param name="op" value="op"></pg:param>
<pg:param name="niming" value="0"></pg:param>
<jsp:include page="/plugins/paging/jsp/altavista.jsp"
flush="true" />
<!-- 从page对象中取得属性值firstItem , lastIterm -->
<pg:page export="firstItem, lastItem">
<font color="red">本页 <strong><%=firstItem%>
</strong> -- <strong> <%=lastItem%> </strong>条 <strong>/</strong>
总记录数 <strong><bean:write name="resultSizeDetail" />
</strong>条 </font>
</pg:page>
</pg:pager>