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 );