📄 paging.java
字号:
package org.javabb.infra;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import com.opensymphony.xwork.ActionContext;
/*
* Copyright 2004 JavaFree.org
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**
* $Id: Paging.java,v 1.7.10.2 2006/04/17 17:47:16 daltoncamargo Exp $
* @author Dalton Camargo - <a href="mailto:dalton@javabb.org">dalton@javabb.org </a> <br>
*/
public class Paging {
/**
* @param recordsPerPage - Registros por p醙ina
* @param nroRecords - N鷐ero total de registros
* @return Retorna o n鷐ero de p醙inas
*/
public static int getNroPages(long recordsPerPage, long nroRecords) {
double pages = Math.ceil((double) nroRecords / recordsPerPage);
return (int) Math.round(pages);
}
/**
* @param pageNumber
* @param totalRows
*/
public static void setPageList(long pageNumber, long totalRows) {
ArrayList pages = new ArrayList();
if ((pageNumber - 3) > 0) {
for (long i = (pageNumber - 3); i < pageNumber; i++) {
pages.add("" + i);
}
} else {
for (long i = 1; i < pageNumber; i++) {
pages.add("" + i);
}
}
if ((pageNumber + 3) <= totalRows) {
for (long i = pageNumber; i <= (pageNumber + 3); i++) {
pages.add("" + i);
}
} else {
for (long i = pageNumber; i <= totalRows; i++) {
pages.add("" + i);
}
}
// Insere o conte鷇o das p醙inas na sess鉶
ActionContext ctx = ActionContext.getContext();
Map session = ctx.getSession();
session.put("pages", pages);
// Insere a 鷏tima p醙ina na sess鉶
session.put("last_page", new Integer((int) totalRows));
}
/**
* Create a list of six pages, when the number of pages will be greater that ten
* @param nroPages
* @return list
*/
public static List createQuickPaging(int nroPages) {
ArrayList pages = new ArrayList();
if (nroPages >= 10) {
pages.add(new Integer(1));
pages.add(new Integer(2));
pages.add(new Integer(3));
pages.add("...");
pages.add(new Integer(nroPages - 2));
pages.add(new Integer(nroPages - 1));
pages.add(new Integer(nroPages));
} else {
for (int i = 1; i <= nroPages; i++) {
pages.add(new Integer(i));
}
}
return pages;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -