pagination in java?

前端 未结 4 439
孤街浪徒
孤街浪徒 2021-01-03 10:12

i want the numbers to be displayed in this format..

1 2 3 4 5 ^
where if i press 5, then it should display from 5 to 10

5 6 7 8 9 10

til

4条回答
  •  刺人心
    刺人心 (楼主)
    2021-01-03 10:33

    We cannot give the specific/exact answer you expected. The thing here is we can give you some advice for some logic ways to accomplish your request.

    First thing is, read some documents for creating a well designed structure of your pagination. Here are some links that may help you in building the design of your pagination.

    • Implementing Search Result Pagination in a Web Application
    • A Pagination Technique Using Spring
    • Pagination: Server Side or Client Side?

    For my personal experience in designing my pagination and a large data will retrieve from a database. I'll use a LIMIT in my sql query to fasten retrieving the results. And I'll do things as follows.

    • First I do have a Model a class/object that will hold the pages that will display in my presentation layer.
    • The processing of query will process in a DAO/my business layer.
    • Now in my Services/Logic layer will process the assigning of values to my model. This where also the forwarding and requesting of data will be handle.
    • And in my presentation layer which the results of the query and the parameter for every links in pagination will display.

    I know my explanation is not clear but I hope you get some point on it.

    And now you could ask what's the relevant to your question. It is the process of how your presentation communication with your business layer. What I mean is the flow on how will you get the result you needed if some page number was call. Seems not really clear for that I'll make pseudo-codes that more related to you're question.

    Since you don't have a ( First | Prev | page no here.... | Next | Last ) on your pagination. I'll make it short as possible.

    First loading of the page with default pages. Assuming page data is from database and with the use of LIMIT

    1. DAO/Business - SELECT pagesContent/link FROM someTables LIMIT 0,5;..
    2. Services/Logic - Put links for page 1 and so on... and put it to pagination Model..
    3. Presentaton/Display - Display now the pages that stored in pagination Model.. Now in page5 or the last page you get the query you will pass another parameter that will change the starting limit of the query and you can pass also the nth page..

    The logic here is, from your pagination display you will need to pass a value that your logic layer will understand what will be the next pages to be display. Another way is you can set a condition in you logic layer how to count the pages if it is not in the range of 1 - 4 or other thing you need to validate.

    I hope this can be a help.

提交回复
热议问题