求一个struts+hibernate分页的实例,详细点的最好能写到v层谢谢!~~ 如题,非常感谢~~~ 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 public List selectAttached(int page, int end) throws HibernateException { List list = null; try { session = HibernateSessionFactory.getSession(); tx = session.beginTransaction(); int pages = (page - 1) * end; String hql = " from Attached " ; Query query = session.createQuery(hql); query.setFirstResult(pages); // 设置开始 的条数 if (end > 0) { query.setMaxResults( end);// 设置最大的条数 } list = query.list(); } catch (HibernateException e) { e.printStackTrace(); Logs.writeWarn(logger, "查询失败"); } finally { try { session.close(); } catch (HibernateException e) { Logs.writeWarn(logger, "session关闭失败"); } } return list; } --------action-------------------------------------------------- String pages = request.getParameter("page");// 取前台分页的传递过来的值 int page; List list = null; List listcount = null; int app = 20; // 每页20条记录 AttachedDAO attacheddao = new AttachedDAO(); String coun = request.getParameter("count"); // 以下是初始化值 if (pages == null || pages.equals("")) {// 如果调用页面没有传递 要查询的页码 给予默认值 第一页 page = 1; } else { page = Integer.parseInt(pages); } try { list = attacheddao.selectAttached(page, app);// 查询 相应的记录 } catch (Exception e) { e.printStackTrace(); } if (coun == null || coun.equals("")) { try { listcount = attacheddao.selectAttached(1, 0);// 取总记录条数 request.setAttribute("count", listcount.size());// 保存总记录条数 } catch (Exception e) { e.printStackTrace(); } } else { request.setAttribute("count", request.getParameter("count"));// 总记录条数 } request.setAttribute("attached", list);// 查询的记录 if(findKeyWordForm.getKey()!=null){ listcount = companydao.selectCompanyLike(findKeyWordForm.getKey()); request.setAttribute("count", listcount.size());// 总记录条数 } request.setAttribute("app", app); // 每页多少条记录 request.setAttribute("page", page); // 当前前面 return mapping.findForward("success");// 页面跳转-------------------jsp-----------------------------------------------<% String count = request.getAttribute("count").toString();//总共多少条记录 String pagea = request.getAttribute("page").toString();//当前页 String app = request.getAttribute("app").toString();//每页多少条记录 int allpage = 0;//总共多少页码 // int jisuan=Integer.parseInt(count); if (Integer.parseInt(count) % Integer.parseInt(app) > 0) { allpage = Integer.parseInt(count) / Integer.parseInt(app) + 1; } else { allpage = Integer.parseInt(count) / Integer.parseInt(app); } //下一页和上一页 int downpage = Integer.parseInt(pagea) + 1; int uppage = Integer.parseInt(pagea) - 1;%>总共 <%=count%> 条记录 / 每页<%=app%>条记录 总共 <%=String.valueOf(allpage)%> 页面 / 当前第 <%=pagea%> 页 <% if (Integer.parseInt(pagea.trim()) <= 1) { out.print("首页"); } else { %> <a href="/DeviceManage/findKeyWord.do?<%=keyWord%>page=1&count=<%=count%>">首页</a> <% } if (uppage > 0) { %> <a href="/DeviceManage/findKeyWord.do?<%=keyWord%>page=<%=String.valueOf(uppage)%>&count=<%=count%>">上一页</a> <% } else { out.print("上一页"); } if (downpage <= allpage) { %> <a href="/DeviceManage/findKeyWord.do?<%=keyWord%>page=<%=String.valueOf(downpage)%>&count=<%=count%>">下一页</a> <% } else { out.print("下一页"); } if (Integer.parseInt(pagea.trim()) >= allpage) { out.print("尾页"); } else { %> <a href="/DeviceManage/findKeyWord.do?<%=keyWord%>page=<%=String.valueOf(allpage)%>&count=<%=count%>">尾页</a> <% } %> 我已经穷得饭都吃不上了,我只有6分~!!Thank you 呵呵 more helpness more quartz任务调度 jquery append 疑问? jacob 报个小错,来看看 2008-10-23发布的最新的SSH2实战源码及配套视频下载 log4j 的 文件回滚日志 和 普通文件日志 生成的 文件 并无区别阿?请高手指点 java程序的发布 紧急求助,MyBatis的自动映射Mapper接口支持重载吗? Eclipse和J2EE SDK的疑问?(偶超菜,莫笑偶) ·#·#·看来还是这儿高手多一些,swing的jComboBox控件如何实现显示和值分离?急急急急急 ProcessBuilder 使用异常问题 关于OSGI web应用的一个小问题 JAVA中的单子模式
List list = null;
try { session = HibernateSessionFactory.getSession();
tx = session.beginTransaction();
int pages = (page - 1) * end;
String hql = " from Attached " ; Query query = session.createQuery(hql);
query.setFirstResult(pages); // 设置开始 的条数
if (end > 0) {
query.setMaxResults( end);// 设置最大的条数
}
list = query.list();
} catch (HibernateException e) {
e.printStackTrace();
Logs.writeWarn(logger, "查询失败");
} finally {
try {
session.close();
} catch (HibernateException e) {
Logs.writeWarn(logger, "session关闭失败"); }
} return list; }
String pages = request.getParameter("page");// 取前台分页的传递过来的值
int page;
List list = null;
List listcount = null;
int app = 20; // 每页20条记录
AttachedDAO attacheddao = new AttachedDAO();
String coun = request.getParameter("count");
// 以下是初始化值 if (pages == null || pages.equals("")) {// 如果调用页面没有传递 要查询的页码 给予默认值 第一页
page = 1;
} else {
page = Integer.parseInt(pages);
} try {
list = attacheddao.selectAttached(page, app);// 查询 相应的记录
} catch (Exception e) {
e.printStackTrace(); } if (coun == null || coun.equals("")) {
try {
listcount = attacheddao.selectAttached(1, 0);// 取总记录条数
request.setAttribute("count", listcount.size());// 保存总记录条数
} catch (Exception e) {
e.printStackTrace(); } } else {
request.setAttribute("count", request.getParameter("count"));// 总记录条数 }
request.setAttribute("attached", list);// 查询的记录
if(findKeyWordForm.getKey()!=null){
listcount = companydao.selectCompanyLike(findKeyWordForm.getKey());
request.setAttribute("count", listcount.size());// 总记录条数
}
request.setAttribute("app", app); // 每页多少条记录
request.setAttribute("page", page); // 当前前面 return mapping.findForward("success");// 页面跳转
-------------------jsp-----------------------------------------------
<% String count = request.getAttribute("count").toString();//总共多少条记录
String pagea = request.getAttribute("page").toString();//当前页
String app = request.getAttribute("app").toString();//每页多少条记录
int allpage = 0;//总共多少页码
// int jisuan=Integer.parseInt(count);
if (Integer.parseInt(count) % Integer.parseInt(app) > 0) {
allpage = Integer.parseInt(count) / Integer.parseInt(app) + 1;
} else {
allpage = Integer.parseInt(count) / Integer.parseInt(app);
}
//下一页和上一页
int downpage = Integer.parseInt(pagea) + 1;
int uppage = Integer.parseInt(pagea) - 1;%>总共
<%=count%>
条记录 / 每页<%=app%>条记录 总共
<%=String.valueOf(allpage)%>
页面 / 当前第
<%=pagea%>
页
<%
if (Integer.parseInt(pagea.trim()) <= 1) {
out.print("首页");
} else {
%>
<a
href="/DeviceManage/findKeyWord.do?<%=keyWord%>page=1&count=<%=count%>">首页</a> <%
} if (uppage > 0) {
%>
<a
href="/DeviceManage/findKeyWord.do?<%=keyWord%>page=<%=String.valueOf(uppage)%>&count=<%=count%>">上一页</a>
<%
} else {
out.print("上一页");
}
if (downpage <= allpage) {
%>
<a
href="/DeviceManage/findKeyWord.do?<%=keyWord%>page=<%=String.valueOf(downpage)%>&count=<%=count%>">下一页</a>
<%
} else {
out.print("下一页");
}
if (Integer.parseInt(pagea.trim()) >= allpage) {
out.print("尾页");
} else {
%>
<a
href="/DeviceManage/findKeyWord.do?<%=keyWord%>page=<%=String.valueOf(allpage)%>&count=<%=count%>">尾页</a> <%
}
%>