Struts Development Practice - Paging Implementation

zhaozj2021-02-16  54

Struts Development Practice - Paging Implementation

The main function of this case is to complete the paging display of the data set. The sample code is as follows:

1.PageInfo class: Define Pipe Information.

/ ****************** Program Begin ************************** /

Package test;

Import java.io. *;

Public Final Class PaginationInfo

IMPLEMENTS SERIALIZABLE {

/ ** Page size Description How many lines per page * /

Private int pagesize = 20;

/ ** Is there a previous page * /

Private Boolean Hasprevious

/ ** Is there a next page * /

Private boolean hasnext;

/ ** total number * /

PRIVATE INT TOTAL;

/**total pages */

Private int totalpage;

/ ** Current page number * /

Private int currentpagenumber = 1;

/ ** Jump action: 1: Home; 2: Previous page; 3: Take a page; 4: Last page * /

Private int jumpstate;

Public void setpagesize (int pageize) {

THIS.PAGESIZE = Pagesize;

}

Public int getpagesize () {

Return PageSize;

}

Public void setHasprevious (Boolean Hasprevious) {

THIS.HASPREVIOUS = HaspRevious

}

Public boolean getHasprevious () {

Return Hasprevious;

}

Public void setpreviouspagenumber (int readypagenumber) {

This.Previouspagenumber = previouspagenumber;

}

Public int getpreviouspagenumber () {

Return Previoun PREVIUSPAGENUMBER;

}

Public void sethasnext (Boolean Hasnext) {

THIS.hasnext = HasnexT;

}

Public boolean gethasnext () {

Return hasnexT;

}

Public void setnextpagenumber (int nextpagenumber) {

THIS.NEXTPAGENUMBER = NextPAGenumber;

}

Public int getNextPagenumber () {

Return nextpagenumber;

}

Public void settotal (int total) {

THIS. TOTAL = Total;

}

Public int gettotal () {

Return Total;

}

Public void settotalpage (int totalpage) {

THIS. TOTALPAGE = TotalPage;

}

Public int gettotalpage () {

Return Totalpage;

}

Public void setcurrentpagenumber (int currentpagenumber) {

THIS.CURRENTPAGENUMBER = CURRENTPAGENUMBER;

}

Public int getcurrentpagenumber () {

Return CurrentPagenumber;

}

Public void setjumpState (int JumpState) {this.jumpstate = jumpstate;

}

Public int getJumpState () {

Return jumpstate;

}

}

2. Paging Logic Method Code:

Public void setpageInfo (PAGINATIONINFO PAGINATIONINFO) {

// Jump page

IF (PAGINAFO.GETJUMPSTATE () == 1) {// Home

PAGINATIONINFO.SETCURRENTPAGENUMBER (1);

}

IF (PAGINAFO.GETJUMPSTATE () == 2) {

Paginginfo.setcurrentPagenumber () - 1);

}

IF (PAGINATIONINFO.GETJUMPSTATE () == 3) {

PAGINATIONINFO.SETCURRENTPAGENUMBER (PAGINATIONINFO.GETCURRENTPAGENUMBER () 1);

}

IF (PAGINATIONINFO.GETJUMPSTATE () == 4) {

Paginginfo.setCurrentPagenumber ()); PAGINATIONINFO.GETTOTALPAGE ());

}

INT TOTALPAGE = Total / PAGINATIONINFO.GETPAGESIZE ();

IF (Total% PAGINATIONINFO.GETPAGESIZE ()> 0) {

PAGINATIONINFO.SETTOTALPAGE (TotalPage 1);

}

Else {

PAGINATIONINFO.SETTOTATION (TOTALPAGE);

}

IF (PAGINAFO.GETCURRENTPAGENUMBER () <= 1) {

PAGINATIONINFO.SETCURRENTPAGENUMBER (1);

PAGINATIONINFO.SETHASPREVIOUS (FALSE);

PAGINATIONINFO.SETHASNEXT (TRUE);

}

Else IF (PAGINAFO.GETCURRENTPAGENUMBER ()> =

PAGINATIONINFO.GETTOTALPAGE ()) {

Paginginfo.setCurrentPagenumber ()); PAGINATIONINFO.GETTOTALPAGE ());

PAGINATIONINFO.SETHASNEXT (FALSE);

PAGINATIONINFO.SETHASPREVIOUS (TRUE);

}

Else {

PAGINATIONINFO.SETHASPREVIOUS (TRUE);

PAGINATIONINFO.SETHASNEXT (TRUE);

}

}

3. The page display code excerpt from the JSP page:

home Border =

Home

Previous

Next

Last page

next page Last page

... / / olive

转载请注明原文地址:https://www.9cbs.com/read-21935.html

New Post(0)