Java paging Summary

Source: Internet
Author: User

Java paging Summary

Environment: the database uses MySQL

 

Do not go 1: Add "Previous Page, next page" to the front-end page "......

 

<Ahref = "? Startindex = <% = preindex %> & amp; pagesize = 10 "> previous page </a>

 

<Ahref = "? Startindex = <% = nextindex %> & amp; pagesize = 10 "> next page </a>

 

 

Leave 2: Add code to the JSP page

Recordop c =NewRecordop ();

C. Request = request;

Resultset rs = C. List ("uname ");
// Obtain query records

Stringpreindex = C. getpreindex ();

String nextindex = C. getnextindex ();

 

 

 

Leave 3: Add the following three methods to the backend Java to calculate the index of the previous and next pages.

 

PublicintPagesize = 12;

PublicString getpreindex ()

{

IntCurindex = 0;

If(Request. getparameter ("startindex") =Null)

Return"0 ";

Else

{

Curindex = integer.Valueof(Request. getparameter ("startindex "));

IntPre = curindex-pagesize;

If(Pre <0)

Return"0 ";

Else

ReturnString.Valueof(Pre );

}

}

PublicString getcurindex ()

{

IntCurindex = 0;

If(Request. getparameter ("startindex") =Null)

Return"0 ";

Else

{

Return(Request. getparameter ("startindex "));

}

}

PublicString
Getnextindex ()

{

IntCurindex = 0;

If(Request. getparameter ("startindex") =Null)

{

IntNext = curindex + pagesize;

ReturnString.Valueof(Next );

}

Else

{

Curindex = integer.Valueof(Request. getparameter ("startindex "));

IntNext = curindex + pagesize;

ReturnString.Valueof(Next );

}

}

 

 

Do not go 4: add the list method, query records: The main statement is

 

 

String SQL =
"Select * From vinrecord order by id desc limit" + getcurindex () + "," + String.Valueof(Pagesize );

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.