JSP 分页技术 原创,测试OK,无论数据库有多少数据,可以尽情的翻!
来源:互联网 发布:怎么使用淘宝客买东西 编辑:程序博客网 时间:2024/05/01 15:20
<span style="font-family: Arial, Helvetica, sans-serif;">package accp.hhs.util;</span>
public class PageMoed {private int currentIndex; //当前页private int rowSize; //行大小private int sunPage; //总页数private int beginRow; //起始行private int startIndex; //显示的页码private String order; //排序public String getOrder() {return order;}public void setOrder(String order) {this.order = order;}/** * 起始显示页数 * @return */public int getStartIndex() {for(int i=1;i<=this.getSunPage();i+=8){if(this.getCurrentIndex()>=i&&this.getCurrentIndex()<i+9){startIndex=i;break;}}return startIndex;}/** * 起如行数 * @return */public int getBeginRow() {//起始行, 当前行数-1*行大小beginRow=(currentIndex-1)*rowSize;return beginRow;}public void setBeginRow(int beginRow) {this.beginRow = beginRow;}public int getSunPage() {return sunPage;}//总页数public void setSunPage(int sunRow) {int temp=0;temp=(sunRow%this.getRowSize()==0)?sunRow/this.getRowSize():sunRow/this.getRowSize()+1;System.out.println("总页数: "+temp+" 大小:"+this.getRowSize());this.sunPage=temp;}/** * 当前页 * @return */public int getCurrentIndex() {return currentIndex;}public void setCurrentIndex(String currentIndex) {//如是为空=1if("".equals(currentIndex)||null==currentIndex||!IsNum.isNum(currentIndex)){currentIndex="1";}int currentIndexs=Integer.parseInt(currentIndex);//如果当前页大于总页数if(currentIndexs>=this.getSunPage()){currentIndexs=this.getSunPage();}if(currentIndexs<=0){currentIndexs=1;}this.currentIndex = currentIndexs;}/** * 行数数大小 * @return */public int getRowSize() {if(rowSize<=0){rowSize=2;}return rowSize;}public void setRowSize(int rowSize) {this.rowSize = rowSize;}}
</pre><p>JSP 分页技术 原创,测试OK,无论数据库有多少数据,可以尽情的翻!</p><p>因涉及的代码太多!这只是重心代码,其它就是传值,查询数据库之类的!因该不是什么大问题吧。。。。。。。。</p><p>还是把页面代码贴出来吧</p><p></p><pre name="code" class="html"><div> <p> <a href="${pageContext.request.contextPath}/EmpSerive.do?flag=showEmp¤tIndex=${currentIndex-1}"> 上一页</a> 当前页【${currentIndex}/${totalPage}】 <c:forEach var="i" begin="${satrtIndex}" end="${satrtIndex+9}"> <a href="${pageContext.request.contextPath}/EmpSerive.do?flag=showEmp¤tIndex=${i}"> <c:if test="${currentIndex==i}"> <font color='red'> ${i} </font> </c:if> <c:if test="${currentIndex!=i}">${i} </c:if> </a> </c:forEach> <a href="${pageContext.request.contextPath}/EmpSerive.do?flag=showEmp¤tIndex=${currentIndex+1}"> 下一页</a> <input type="text" size="2" id="valuePage"/> <a href="javascript:PageIndex()">跳转</a> </p> <%--页面跳转 --%> <script type="text/javascript"> function PageIndex(){ var pagev=document.getElementById("valuePage"); location.href="${pageContext.request.contextPath}/EmpSerive.do?flag=showEmp¤tIndex="+pagev.value; } </script> </div>
好吧!把实现类的方法也贴出来吧,看不懂不要怪我哈,因为我做测试用了反射机制,让我看我一下子也看不懂了!哈哈,看你需要的就行了。。
/** * 根据hql分页 */@Overridepublic List<T> getPage(String hql, Object[] paramters, PageMoed pageMeod) {Query query=sessionFactory.getCurrentSession().createQuery(hql);if(paramters!=null){for(int i=0;i<paramters.length;i++){query.setParameter(i,paramters[i]);}}query.setFirstResult(pageMeod.getBeginRow()).setMaxResults(pageMeod.getRowSize());return (List<T>)query.list();}/** * 根据对象分页 */@Overridepublic List<T> getPage(T e, PageMoed pageMeod) throws Exception {Class cla=e.getClass();String tableName=cla.getSimpleName();Field[] field=cla.getDeclaredFields();//得到所有字段//SQL语句接接StringBuffer sb=new StringBuffer();sb.append(" where 1=1 ");//List<Object> listValue=new ArrayList<Object>();//?值拼接for(int i=0;i<field.length;i++){Field f=field[i]; f.setAccessible(true);Object obj=f.get(e); //得到字段的值if(obj instanceof Set){System.out.println("检测到Set.....");((Set) obj).clear();}else// 加? 加值if(!"".equals(obj)&&null!=obj){//如果字段不为空sb.append(" and "+f.getName()+"= "+obj);//listValue.add(obj);} }//如有有排序的话if(pageMeod.getOrder()!=null){sb.append(" "+pageMeod.getOrder());}String hql="from "+tableName+" "+sb.toString();System.out.println("HQL: "+hql);Query query=sessionFactory.getCurrentSession().createQuery(hql);//分页List<T> liste=(List<T>)query.setFirstResult(pageMeod.getBeginRow()).setMaxResults(pageMeod.getRowSize()).list();//那些年return liste;}
</pre><pre name="code" class="html">
</pre><pre name="code" class="html">
</pre><pre name="code" class="html">
</pre><pre name="code" class="html">
</pre><pre name="code" class="html">
</pre><pre name="code" class="html">
</pre><pre name="code" class="html">
</pre><pre name="code" class="html">
</pre><pre name="code" class="html">
</pre><pre name="code" class="html">
</pre><pre name="code" class="html">
</pre><pre name="code" class="html">
</pre><pre name="code" class="html">
</pre><pre name="code" class="html">
</pre><pre name="code" class="html">
</pre><pre name="code" class="html">
</pre><pre name="code" class="html">
</pre><pre name="code" class="html">
</pre><pre name="code" class="html">
</pre><pre name="code" class="html">
</pre><pre name="code" class="html">
</pre><pre name="code" class="html">
</pre><pre name="code" class="html">
</pre><pre name="code" class="html">
</pre><pre name="code" class="html">
</pre><pre name="code" class="html">
</pre><pre name="code" class="html">
</pre><pre name="code" class="html">
</pre><pre name="code" class="html">
</pre><pre name="code" class="html">
</pre><pre name="code" class="html">
</pre><pre name="code" class="html">
</pre><pre name="code" class="html">
</pre><pre name="code" class="html">
</pre><pre name="code" class="html">
</pre><pre name="code" class="html">
</pre><pre name="code" class="html">
</pre><pre name="code" class="html">
</pre><pre name="code" class="html">
</pre><pre name="code" class="html">
</pre><pre name="code" class="html">
</pre><pre name="code" class="html">
</pre><pre name="code" class="html">
</pre><pre name="code" class="html">
</pre><pre name="code" class="html">
</pre><pre name="code" class="html">
</pre><pre name="code" class="html">
</pre><pre name="code" class="html">
</pre><pre name="code" class="html">
</pre><pre name="code" class="html">
</pre><pre name="code" class="html">
</pre><pre name="code" class="html">
- JSP 分页技术 原创,测试OK,无论数据库有多少数据,可以尽情的翻!
- [原创]有多少jj可以重切
- jsp数据库分页技术
- 多态的重要例子--无论当前当前时刻到底有多少个子类对象 都可以把它全部输出
- jsp数据库查询分页技术
- JSP的分页技术
- jsp的分页技术
- 可克 原创 jquery扩展 的 分页对象。有需要的可以下。
- 【基于Verilog的数字频率计设计】原创.上电测试OK
- JSP数据库数据分页显示
- jsp的分页技术与访问数据库的汉字处理
- 数据库分页有重复数据
- JSP分页技术·oracle数据库
- JSP中的分页技术源码(MYSQL数据库)
- 非常好的JSP分页技术
- JSP分页技术的实现
- jsp中分页的技术
- jsp的一些分页技术
- android 开发时遇到的环境问题
- 浅谈su临时切换用户的实现方法
- coding - 求二叉树中节点的最大距离
- Summary_Thinking
- 计算机硬件知识总结
- JSP 分页技术 原创,测试OK,无论数据库有多少数据,可以尽情的翻!
- Servlet——Filter技术
- 数据库与数据仓库的区别
- apache FTPClient下载失败解决方法
- CppUnit测试框架入门
- 利用CMake编译内核模块
- Layout Inflation As Intended
- C++课程设计报告——贪吃蛇和迷宫的设计及实现
- 最大化 JavaScript 应用程序的金科玉律是尽可能使用外部 JavaScript 文件,而不是直接将 JavaScript 代码包含在 HTML 文件中