日期:2014-05-16  浏览次数:20409 次

用Spring的JdbcTemplate实现分页功能

 如果你的查询有10000条记录,或者更多,速度肯定慢了,当然你可以通过resultset中的游标控制查询的起始和结束。我这里用的是Oracle数据库,使用伪列ROWNUM来实现分页。我的分页代码如下:

<!-- Code highlighting produced by Actipro CodeHighlighter (freeware) http://www.CodeHighlighter.com/ -->package com.deity.ranking.util;import java.util.List;   import org.springframework.jdbc.core.JdbcTemplate;   import org.springframework.jdbc.core.support.JdbcDaoSupport;   /** * 分页函数 * * @author allenpan */public class Pagination extends JdbcDaoSupport{   public static final int NUMBERS_PER_PAGE = 10;   //一页显示的记录数   private int numPerPage;   //记录总数   private int totalRows;   //总页数   private int totalPages;   //当前页码   private int currentPage;   //起始行数   private int startIndex;   //结束行数   private int lastIndex;   //结果集存放List   private List resultList;   //JdbcTemplate jTemplate   private JdbcTemplate jTemplate;   /**   * 每页显示10条记录的构造函数,使用该函数必须先给Pagination设置currentPage,jTemplate初值   * @param sql oracle语句   <