求一个用于mvc设计模式的分页的javabean
1个回答
展开全部
public class Pager {
private int totalRows; //总行数
private int pageSize = 5; //每页显示的行数
private int currentPage; //当前页号
private int totalPages; //总页数
private int startRow; //当前页在数据库中的起始行
public Pager(){
}
public Pager(int _totalRows){
totalRows = _totalRows;
totalPages = totalRows/pageSize;
int mod = totalRows%pageSize;
if(mod>0){
totalPages++;
}
currentPage = 1;
startRow = 0;
}
public int getTotalRows() {
return totalRows;
}
public void setTotalRows(int totalRows) {
this.totalRows = totalRows;
}
public int getPageSize() {
return pageSize;
}
public void setPageSize(int pageSize) {
this.pageSize = pageSize;
}
public int getCurrentPage() {
return currentPage;
}
public void setCurrentPage(int currentPage) {
this.currentPage = currentPage;
}
public int getTotalPages() {
return totalPages;
}
public void setTotalPages(int totalPages) {
this.totalPages = totalPages;
}
public int getStartRow() {
return startRow;
}
public void setStartRow(int startRow) {
this.startRow = startRow;
}
public void first(){
currentPage = 1;
startRow = 0;
}
public void previous(){
if(currentPage==1){
return;
}
currentPage--;
startRow = (currentPage - 1)*pageSize;
}
public void next(){
if(currentPage < totalPages){
currentPage++;
}
startRow = (currentPage - 1)*pageSize;
}
public void last(){
currentPage = totalPages;
startRow = (currentPage - 1)*pageSize;
}
public void refresh(int _currentPage){
currentPage = _currentPage;
if (currentPage > totalPages) {
last();
}
}
}
public class PagerServer {
public Pager getPager(String currentPage,String pagerMethod,int totalRows) {
//定义pager对象,用于传到页面
Pager pager = new Pager(totalRows);
//如果当前页号为空,表示为首次查询该页
//如果不为空,则刷新pager对象,输入当前页号等信息
if (currentPage != null) {
pager.refresh(Integer.parseInt(currentPage));
}
//获取当前执行的方法,首页,前一页,后一页,尾页。
if (pagerMethod != null) {
if (pagerMethod.equals("first")) {
pager.first();
} else if (pagerMethod.equals("previous")) {
pager.previous();
} else if (pagerMethod.equals("next")) {
pager.next();
} else if (pagerMethod.equals("last")) {
pager.last();
}
}
return pager;
}
}
private int totalRows; //总行数
private int pageSize = 5; //每页显示的行数
private int currentPage; //当前页号
private int totalPages; //总页数
private int startRow; //当前页在数据库中的起始行
public Pager(){
}
public Pager(int _totalRows){
totalRows = _totalRows;
totalPages = totalRows/pageSize;
int mod = totalRows%pageSize;
if(mod>0){
totalPages++;
}
currentPage = 1;
startRow = 0;
}
public int getTotalRows() {
return totalRows;
}
public void setTotalRows(int totalRows) {
this.totalRows = totalRows;
}
public int getPageSize() {
return pageSize;
}
public void setPageSize(int pageSize) {
this.pageSize = pageSize;
}
public int getCurrentPage() {
return currentPage;
}
public void setCurrentPage(int currentPage) {
this.currentPage = currentPage;
}
public int getTotalPages() {
return totalPages;
}
public void setTotalPages(int totalPages) {
this.totalPages = totalPages;
}
public int getStartRow() {
return startRow;
}
public void setStartRow(int startRow) {
this.startRow = startRow;
}
public void first(){
currentPage = 1;
startRow = 0;
}
public void previous(){
if(currentPage==1){
return;
}
currentPage--;
startRow = (currentPage - 1)*pageSize;
}
public void next(){
if(currentPage < totalPages){
currentPage++;
}
startRow = (currentPage - 1)*pageSize;
}
public void last(){
currentPage = totalPages;
startRow = (currentPage - 1)*pageSize;
}
public void refresh(int _currentPage){
currentPage = _currentPage;
if (currentPage > totalPages) {
last();
}
}
}
public class PagerServer {
public Pager getPager(String currentPage,String pagerMethod,int totalRows) {
//定义pager对象,用于传到页面
Pager pager = new Pager(totalRows);
//如果当前页号为空,表示为首次查询该页
//如果不为空,则刷新pager对象,输入当前页号等信息
if (currentPage != null) {
pager.refresh(Integer.parseInt(currentPage));
}
//获取当前执行的方法,首页,前一页,后一页,尾页。
if (pagerMethod != null) {
if (pagerMethod.equals("first")) {
pager.first();
} else if (pagerMethod.equals("previous")) {
pager.previous();
} else if (pagerMethod.equals("next")) {
pager.next();
} else if (pagerMethod.equals("last")) {
pager.last();
}
}
return pager;
}
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询