微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

使用Java在Google App Engine中分页

我需要创建简单的对象分页,但是当我阅读手册时,我发现了query.setRange(5,10);将获取10个对象,即使只需要5个对象.

反正有没有获取所需的对象?

编辑:我开始赏金,所以你可以向我展示Java中的简单示例代码,然后我会接受你的回答.

解决方法

这个怎么样:
List<Employee> results = (List<Employee>) query.execute();
// Use the first 20 results...

Cursor cursor = JPACursorHelper.getCursor(results);
String cursorString = cursor.toWebSafeString();
// Store the cursorString...

// ...

// Query query = the same query that produced the cursor
// String cursorString = the string from storage
Cursor cursor = Cursor.fromWebSafeString(cursorString);
query.setHint(JPACursorHelper.CURSOR_HINT,cursor);
query.setRange(0,20);

List<Employee> results = (List<Employee>) query.execute();
// Use the next 20 results...

从:

How to use datastore cursors with jpa on GAE

也:

http://groups.google.com/group/google-appengine-java/browse_thread/thread/5223215ff24c3b3e/d22297d1d76a9c8b

或者没有JPA,请参阅:

http://code.google.com/appengine/docs/java/javadoc/com/google/appengine/api/datastore/Cursor.html

原文地址:https://www.jb51.cc/java/129044.html

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐