我的 RPC 服务中有这个方法:
@Override
public Entrata[] getEntrate(int from, int to) {
List<Entrata> data = entrateDao.list();
return data.toArray(new Entrata[0]);
}
正如您所看到的,我没有使用这两个参数,在 SQL 世界中,我将使用这两个参数作为 LIMIT 和 OFFSET。
目前还不完全清楚我现在必须做什么,我开始阅读以下内容:http://code.google.com/p/objectify-appengine/wiki/IntroductionToObjectify#Cursors
我想我必须做一个query.startCursor(<my_"from"_parameter>)
然后迭代“TO”次,即页面大小。
好的?你能帮我一些片段吗? :)
来自文档:游标允许您在查询结果集中获取“检查点”,将检查点存储在其他位置,然后从上次中断的位置继续
由于您只需要限制/偏移,因此您必须使用limit()
and offset()
对象化查询的方法。喜欢:
ob.query(Entrata.class).limit(to - from).offset(from)
或者,当您有光标时:
String cursor = // get it from request
Query<Entrata> query = ob.query(Entrata.class);
Query q = query.startCursor(Cursor.fromWebSafeString(cursor));
q.limit(x);
QueryResultIterator<Entrate> iterator = query.iterator()
List<Entrate> data = // fetch data
String newCursor = iterrator.getStartCursor().toWebSafeString()
return new EntrataListWithCursor(data, cursor);
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)