Sorting out Java Paging ideas

Source: Internet
Author: User

Today just credits page also some not very clear want to tidy up a bit.

1. Create a database to put the data you want to display in the table

2. Start writing code. Write a JavaBean Create database properties for Access

3. Create a database query class There are two methods in this class. A method returns the property values in the data table and sets the Display method (set to: Select Top "with SQL statements) Number of rows displayed per page "*from UserInfo where ID not in ((current page-1) * Number of rows per page)" ID from UserInfo ORDER by ID) the value that is taken out of the array (set) to store the method passed in two parameters as follows:

1) . Number of lines displayed per page

2) . Current page number

Another method returns the total number of data rows in the database table

4. (emphasis) Adjust the display of the page this class has a method method for page display with three parameters, respectively, as follows

1) . Total number of rows (value in the method that returns the total number of rows in the database query class just now)

2) . How many rows of data are displayed per page

3) . Current page number

number of rows per page in this method = Total pages

The total number of pages to be saved with an int so that the result is an integer (the numbers after the decimal point are removed)

so we use the method of seeking redundancy to determine the total number of pages% of rows per page = remainder

if the remainder >0 Let the total number of pages 1 so that really get the total number of pages

Now you know four numbers (1. Total number of rows 2. Number of lines displayed per page 3. The current page 4. Total pages) The next step is to set up the page.

The strength of the StringBuffer with this class of append () method to determine after appending the HTML code to the Web page

Judging: If the current page is the first page, then the word ' first page ' will not need a link Otherwise, the word ' first page ' is linked and can jump to ' current page-1 ' page

Judging: If the current page number is 0 or negative, the current page number is set to 1 otherwise the current page number is displayed normally

judgment: If the current page number exceeds the total page number, the current page number is set to the last page Otherwise, the current page number is displayed normally

judge: Set the initial value to display the page number correctly if the page number is displayed normally Start looping the HTML page code to the user display and can select the maximum number of pages for this loop because: ' No more than the total page count '

Judging: If one of the page numbers that is printed on the loop is exactly the current page number Then the page number does not set the link otherwise all other settings link and can jump to the page number of pages ...

judgment: If it is greater than the current page 2 (or 3 4) and is less than the total number of pages: . Instead (that is, the page number in the middle of the two and last page of the current page and the current page number is replaced by an ellipsis)

judge: if the current page page is the "next page" Word does not set the link otherwise the ' next page ' word set the link And can be connected to ' current Page 1 '

This class returns stringbuffer

5. The JSP is set up: Pour the previously created class into the JSP to declare an array (collection) and call the first method of the data query class and pass in the parameters. Then use a Request.setattribute () method to store the array (set) inside and walk out of the page display class (The fourth step creates the class)

It's done, now go ahead and write the code.


Sorting out Java Paging ideas

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.