If we want to implement the Java paging technology, we need to define four variables first, they are:
int pagesize;//How many records are displayed per page
int pagenow;//Hope Reality first few pages
int pagecount;//How many pages there are altogether
int rowcount;//How many records are there altogether?
Description
1.pageSize is the specified
2.pageNow is the user's choice
3.rowCount is the query from the table
The 4.pageCount is calculated, and the calculation is:
if (rowcount%pagesize==0)
{
Pagecount=rowcount/pagesize;
}
Else
{
pagecount=rowcount/pagesize+1;
}
The above note may listen to a little foggy, I would like to give an example to specify:
There are user tables, a total of 9 records, namely: rowCount; Each page shows 3 records, namely: pagesize=3; then according to our algorithm: pagecount=3, just not much more, if each page shows four records, Pagesize=4, then pagecount= 3, the last page will only have 1 records, so it is correct anyway.
In response to the previous question, it is easy to think of the use of the Select field list from the table name where ID between? and?
We use a users table as an example to show the third page, the query statement is: SELECT * from the users userId between 7 and 9;
This SQL statement is really fast, but it has a problem, that is, if the ID of the table is deleted, then a page may be missing a record. Experiment with SQL Server's Query Analyzer, so our final solution is the following statement:
Select top pageSize field list from table name where ID not in (select Top pagesize* (pageNow-1) ID from table name);
Talking about Java paging technology