首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > 编程 >

Java分页步骤探讨

2012-11-15 
Java分页方法探讨闲来无事,写了个分页的功能测试,列举了两种处理分页的方法,如果大家有其他的想法,欢迎评

Java分页方法探讨

闲来无事,写了个分页的功能测试,列举了两种处理分页的方法,如果大家有其他的想法,欢迎评论!代码如下:

import java.util.ArrayList;import java.util.List;public class Test {/** * @param args */public static void main(String[] args) {List<String> rowsData = new ArrayList<String>();int rows = 7;//总计录数int rowsOfPage = 3;//每页记录数int pages = (rows + rowsOfPage - 1) / rowsOfPage;//总页数System.out.println("总记录数:"+rows + "、总页数:" + pages + "、每页记录数:" + rowsOfPage);// 填充模拟数据for (int i = 0; i < rows; i++) {rowsData.add("记录" + i);}int t = 0;System.out.println("判断分页方法一");for (int i = 0; i < pages; i++) {for (int j = 0; j < rowsOfPage; j++) {System.out.print(rowsData.get(t++) + " | ");if (t == rows)break;}System.out.println();}System.out.println("判断分页方法二");for (int i = 0; i < rows; i++) {for (int j = 0; j < rowsOfPage; j++) {System.out.print(rowsData.get(i++) + " | ");if (i == rows) {break;}}i--;System.out.println();}}}
? 1 楼 cyhcheng 2011-08-04   好久没上,不好意思啊,在这主要是讨论下基础内容,实际项目开发基本都是采用框架。
分页实现有采用
1、数据库端分页查询、预检索,适合海量数据的
2、程序分页,适合小数据量基本



热点排行