简体   繁体   English

Arraylist中的子列表与SQL中的限制

[英]Sublist in Arraylist vs limit in SQL

I am working on a grid with pagination.. I have to display 10 rows in a grid each time. 我正在分页处理网格。每次必须在网格中显示10行。 So Database may contains max of 1000 rows(mostly wont exceed 500 records). 因此,数据库最多可以包含1000行(大多数情况下不会超过500条记录)。

So will be good to pull all the records and then apply Array.sublist(start, end) OR SQL query with LIMIT(start, end)? 那么拉取所有记录然后应用Array.sublist(start,end)或带有LIMIT(start,end)的SQL查询会很好吗?

Thanks 谢谢

The best solution would be to go with offset and limit. 最好的解决方案是使用偏移量和限制。 Best applications are when you don't cache too much and you are saving resources. 最好的应用程序是当您不缓存太多并且节省资源时。 Think more stateless, less you store, better your application works. 考虑更多的无状态状态,减少存储量,更好地运行应用程序。

If you are using Hibernate you can add caches that will store those records (3-rd level cache -for queries), then Hibernate will cache them for you, but this level of cache is also not recommended. 如果您使用的是Hibernate,则可以添加将存储这些记录的缓存(用于查询的三级缓存),然后Hibernate将为您缓存它们,但是也不建议使用此级别的缓存。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM