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 好久没上,不好意思啊,在这主要是讨论下基础内容,实际项目开发基本都是采用框架。