Paging in Google App Engine Using Java

I need to create a simple object page, but when I read the manual, I found query setRange(5,10); Will get 10 objects, even if only 5 objects are needed

Did you get the required object anyway?

Editor: I started the bounty, so you can show me the simple sample code in Java, and then I will accept your answer

Solution

How's 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:

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

Or no JPA, see:

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

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>