1、查询所有

@Test
public void query() throws Exception {
final Query<Employee> query = datastore.createQuery(Employee.class);
final List<Employee> list = query.asList();
list.forEach(e -> Console.log("{}", e));
}

输出:

Employee(id=5bcef23890c1d9280c07128e, name=小弟1, manager=null, directReports=[], salary=2000.0)
Employee(id=5bcef23890c1d9280c07128f, name=小弟2, manager=null, directReports=[], salary=3000.0)
Employee(id=5bcef23890c1d9280c071290, name=zuoys, manager=null, directReports=[Employee(id=5bcef23890c1d9280c07128e, name=小弟1, manager=null, directReports=[], salary=2000.0), Employee(id=5bcef23890c1d9280c07128f, name=小弟2, manager=null, directReports=[], salary=3000.0)], salary=10000.0)
Employee(id=5bcef45d90c1d91d509941cd, name=小弟3有父, manager=Employee(id=5bcef23890c1d9280c071290, name=zuoys, manager=null, directReports=[Employee(id=5bcef23890c1d9280c07128e, name=小弟1, manager=null, directReports=[], salary=2000.0), Employee(id=5bcef23890c1d9280c07128f, name=小弟2, manager=null, directReports=[], salary=3000.0)], salary=10000.0), directReports=[], salary=22.0)

使用asList()是可以的,但实际上,fetch()通常是更好的选择。

2、条件过滤

//条件过滤-field
@Test
public void query2() throws Exception {
List<Employee> list = datastore.createQuery(Employee.class)
.field("salary").lessThanOrEq(22)
.asList();
list.forEach(e -> Console.log("{}", e));
}
//条件查询-filter
@Test
public void query3() throws Exception {
List<Employee> list = datastore.createQuery(Employee.class)
.filter("salary <=", 22)
.asList();
list.forEach(e -> Console.log("{}", e));
}

使用filter比fiele更简洁,但要注意语法。

最新文章

  1. Smallest Common Multiple
  2. React Native移动框架功能研究
  3. [CareerCup] 6.3 Water Jug 水罐问题
  4. UITabBarController加载之后不显示sub view controller
  5. Android Volley源码分析
  6. php-fpm正在生成页面时,浏览器刷新后,php-fpm会退出吗?
  7. Android中用Application类实现全局变量
  8. node-sqlite3-API-归纳总结
  9. Exameple014实现html中checkbox的全选,反选和全不选(1)
  10. ionic3 app 退出应用程序
  11. html js文字左右滚动插件
  12. Ajax 模糊查询的简单实现
  13. Fullpage参数说明
  14. python 生产者 --- 消费者
  15. BZOJ 3684 大朋友和多叉树
  16. ss with kcptun
  17. 从换脸到换姿势,AI 在图像处理的道路上越走越魔幻
  18. 错误:22 http://ppa.launchpad.net/fkrull/deadsnakes/ubuntu bionic Release 404 Not Found [IP: 91.189.95.83 80]
  19. Docker启动一个Centos镜像
  20. Structs复习 通配符

热门文章

  1. 狂配Nginx
  2. Chrome 插件 Vimium——让你脱离鼠标
  3. xml文件的解析(用dom4j解析)
  4. 确定mapkeeper使用的leverdb库路径
  5. poj-3666
  6. 配置react+webpack+es6中的一些教训
  7. 数据摘要pandas
  8. MongoDB分析工具之三:db.currentOp()
  9. CSS:CSS 颜色
  10. opencv MatExpr MatOp