决定一个战略分页图书清单没有SQL [英] Deciding on a strategy for paginating Book listings without SQL

查看:107
本文介绍了决定一个战略分页图书清单没有SQL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

图书的ArrayList ■从不同的商户拉和Java中的排序,根据用户的preferences,根据价格或顾客评论:

I have an ArrayList of Books pulled from different Merchants and sorted in Java, depending on user preferences, according to price or customer reviews:

List<Book> books = new ArrayList<Book>();

这需要我保持一大块数据的存储与Java在任何时候都对象的内存。现在,我需要分页数据导入跨越多个网页列表并允许用户点击一个编号页面链接一跳数据的段,什么是做到这一点的最好方法是什么?

This requires me to keep a large chunk of data in memory stored as Java objects at all times. Now that I need to paginate this data into listings that span multiple web pages and allow a user to click on a numbered page link to hop to that segment of the data, what's the best way to do this?

我的想法是有可能每页的 25本书目录并而不是使用提交表单数据作为URL的 GET 要求超链接参数,页码链接只会重新提交表单,传递请求的页面数为另一种形式 POST 参数。

My idea was to have maybe 25 book listings per page and rather than use hyperlinks that submit the form data as a GET request of URL parameters, the page number hyperlinks would simply resubmit the form, passing the requested page number as an additional form POST parameter.

<input type="hidden" id="pageNumber" value="0">
<a href="#" onClick="pageNumber=5; this.form.submit()">Page 5</a>

在这种情况下,第5页,简直是开始在的ArrayList 125(5 * 25)记录并且在第149位的记录结束了一组25个记录的ArrayList

In that case page 5 would simply be a set of 25 records starting at the 125th (5 * 25) record in the ArrayList and ending at the 149th record in the ArrayList.

有没有更好的方法来做到这一点?

Is there a better way to do this?

推荐答案

重构应用程序,让如Hibernate的从底层数据库中拉出来的数据。

Refactor your application to let e.g. Hibernate pull out data from the underlying database.

Hibernate可以做所有的排序和分页无需你让这一切在内存中在所有时间。

Hibernate can do all the sorting and pagination without you having to keep it all in memory at all times.

这篇关于决定一个战略分页图书清单没有SQL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆