Xutils 按条件查找

//
  1. Parententity = db.findById(Parent.class, parent.getId());
  2. Parententity = db.findFirst(entity);//通过entity的属性查找
  3. List<Parent>list = db.findAll(entity);//通过entity的属性查找
  4. List<Parent>list = db.findAll(Parent.class);//通过类型查找
  5. ParentParent =db.findFirst(Selector.from(Parent.class).where("name","=","test"));
  6. //IS NULL
  7. ParentParent = db.findFirst(Selector.from(Parent.class).where("name","=",null));
  8. //IS NOT NULL
  9. ParentParent = db.findFirst(Selector.from(Parent.class).where("name","!=",null));
  10. //WHERE id<54 AND (age>20 OR age<30) ORDER BY id LIMITpageSize OFFSET pageOffset
  11. List<Parent>list = db.findAll(Selector.from(Parent.class)
  12.                                   .where("id","<", 54)
  13.                                   .and(WhereBuilder.b("age",">", 20).or("age", " < ", 30))
  14.                                   .orderBy("id")
  15.                                   .limit(pageSize)
  16.                                   .offset(pageSize* pageIndex));
  17. //op为"in"时,最后一个参数必须是数组或Iterable的实现类(例如List等)
  18. Parenttest = db.findFirst(Selector.from(Parent.class).where("id","in", new int[]{1, 2, 3}));
  19. //op为"between"时,最后一个参数必须是数组或Iterable的实现类(例如List等)
  20. Parenttest = db.findFirst(Selector.from(Parent.class).where("id","between", new String[]{"1", "5"}));
  21. DbModeldbModel =db.findDbModelAll(Selector.from(Parent.class).select("name"));//select("name")只取出name列
  22. List<DbModel>dbModels =db.findDbModelAll(Selector.from(Parent.class).groupBy("name").select("name","count(name)"));
  23. ...
  24. List<DbModel>dbModels = db.findDbModelAll(sql); // 自定义sql查询
  25. db.execNonQuery(sql)// 执行自定义sql

你可能感兴趣的:(Xutils 按条件查找)