English 中文(简体)
pagination in java?
原标题:pagination in java?

i 想要以这种格式显示数字。

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

5、6、7、9、10、10、5、6、7、8、9、10、10、5、6、7、8、9、10、10、9、10、10、9、10、10、9、10、10、10、5、6、7、8、9、10、10、10、10、10、5、6、7、8、9、10、10、10、10、10、10、10、5、6、7、9、10、10、10、10、5、6、6、7、9、10、10、10、10、10、10、5、5、6、6、6、7、7、7、7、7、7、9、9、9、9、9、10、9、9、9、10、10、9、10、10、10、10、10、10、10、10、10、10、9、9、10、10、9、10、10、10、10、10、10、10、10、10、9、10、10、10、10、10、10、10、10、10、

till the max records are available. i just want to know a how to do this for displaying numbers.

最佳回答

Normally you want your database to do the heavy lifting for pagination and sorting. With MySQL for example you can get a page of results sorted by date by adding

ORDER BY date ASC LIMIT 5,5

页: 1 如果你使用保密标准,你可以依靠供应商独立的方式这样做:

List<MyDomainClass> results = (List<MyDomainClass>) getSession()     
.createCriteria(MyDomainClass.class)
.setFirstResult(5)
.setMaxResults(5)
.addOrder(Order.asc("date"))
.list();

To display a pagination navigation you also need to count the total number of results to know how many pages there are:

int count = (int) getSession()     
.createCriteria(MyDomainClass.class)
.setProjection(Projections.rowCount())
.list().get(0);

You can add restrictions to both searches, for example when you want to filter on lastname you could add:

.add(Restrictions.eq("lastname", "Smith")

(需要在计票单和清单查询中加上这一点)。

如果你知道结果总数、页数和目前的页数,你就可以计算结果范围,如:

// TODO: execute the count query here to determine totalResults
int totalPages = Math.ceil(totalResults / pageSize);
// show first page by default
int firstResult = 0;
if (currentPage >= 0 && currentPage < totalPages) {
    firstResult = currentPage * pageSize;    
}
// the number of items might be less than the page size (i.e. on the last page)
int count = Math.min(pageSize, totalResults - firstResult);        
// TODO: execute the list query here to get a page of data

你们是如何展示航海的。 有些框架有这方面的标准组成部分。 否则,你就必须想办法处理大量页数。 一种共同做法是展示出10页数,并显示开始/恢复的跳跃,以结束链接。

Hope this helps.

问题回答

我们不能给予你预期的具体/实际答案。 在这里,我们可以向您提供某种逻辑方法,以完成您的要求。

首先,阅读了一些文件,以建立你想象的精心设计的结构。 这里有一些联系可能有助于你建立你的想象力。

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.

上周,我发现了一些原始材料,其中有许多是冷却工具和干get,这里有:。 如果你做些什么是 desktop,那么你可以看一看java

如果您有一份记录清单,则你可以使用<代码>subList方法查询List

List.subList (fromIndex, endIndex);

从Index到Index, 包容性,到Index, 排他性





相关问题
Spring Properties File

Hi have this j2ee web application developed using spring framework. I have a problem with rendering mnessages in nihongo characters from the properties file. I tried converting the file to ascii using ...

Logging a global ID in multiple components

I have a system which contains multiple applications connected together using JMS and Spring Integration. Messages get sent along a chain of applications. [App A] -> [App B] -> [App C] We set a ...

Java Library Size

If I m given two Java Libraries in Jar format, 1 having no bells and whistles, and the other having lots of them that will mostly go unused.... my question is: How will the larger, mostly unused ...

How to get the Array Class for a given Class in Java?

I have a Class variable that holds a certain type and I need to get a variable that holds the corresponding array class. The best I could come up with is this: Class arrayOfFooClass = java.lang....

SQLite , Derby vs file system

I m working on a Java desktop application that reads and writes from/to different files. I think a better solution would be to replace the file system by a SQLite database. How hard is it to migrate ...

热门标签