使用Java在Google App Engine中进行分页 [英] Pagination in Google App Engine with Java
问题描述
我需要创建简单的对象分页,但是当我阅读手册时,我发现query.setRange(5,10);将获取10个对象,即使只需要5个对象。
有没有办法获取刚才需要的对象?
<编辑:我开始赏金,所以你可以告诉我简单的示例代码在Java中的作品,然后我会接受你的答案。
这个如何:
List< Employee> results =(List< Employee>)query.execute();
//使用前20个结果...
Cursor cursor = JPACursorHelper.getCursor(results);
字符串cursorString = cursor.toWebSafeString();
//存储cursorString ...
// ...
//查询查询=产生光标的相同查询
/ / String cursorString =存储的字符串
Cursor cursor = Cursor.fromWebSafeString(cursorString);
query.setHint(JPACursorHelper.CURSOR_HINT,cursor);
query.setRange(0,20);
列表<员工> results =(List< Employee>)query.execute();
//使用下面的20个结果...
发件人:
另外:
或者没有JPA请参阅:
http://code.google.com/appengine/docs /java/javadoc/com/google/appengine/api/datastore/Cursor.html
I need to create simple pagination of objects, but when I read manual I found out that query.setRange(5, 10); will fetch 10 objects, even when only 5 objects are needed.
Is there anyway to fetch just needed objects?
EDIT: I started bounty, so fi you can show me simple example code in Java that works, then I will accept you answer.
How about this:
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...
From:
How to use datastore cursors with jpa on GAE
Also:
Or without JPA see:
http://code.google.com/appengine/docs/java/javadoc/com/google/appengine/api/datastore/Cursor.html
这篇关于使用Java在Google App Engine中进行分页的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!