轻量级数据库框架LitePal - 查询数据

public static synchronized <T> T find(java.lang.Class<T> modelClass, long id, boolean isEager)

查询单条数据.查询第一条数据

  1. News news = DataSupport.find(News.class, 1);  

  1. News firstNews = DataSupport.findFirst(News.class);  

查询多条数据

  1. List<News> newsList = DataSupport.findAll(News.class, 1, 3, 5, 7);  


  1. long[] ids = new long[] { 1, 3, 5, 7 };  

  2. List<News> newsList = DataSupport.findAll(News.class, ids);  


  1. List<News> allNews = DataSupport.findAll(News.class);  


指定条件查询

  1. List<News> newsList = DataSupport.where("commentcount > ?", "0").find(News.class);  

            //查询news表中所有评论数大于零的新闻

 只需要指定的字段

  1. List<News> newsList = DataSupport.select("title", "content")  

  2.         .where("commentcount > ?", "0").find(News.class);  

并且根据指定字段排序

  1. List<News> newsList = DataSupport.select("title", "content")  

  2.         .where("commentcount > ?", "0")  

  3.         .order("publishdate desc").find(News.class);  

只需要前10条数据

  1. List<News> newsList = DataSupport.select("title", "content")  

  2.         .where("commentcount > ?", "0")  

  3.         .order("publishdate desc").limit(10).find(News.class);  

需要10~20条的数据 ,offset:偏移量. 传入10  就是10以后的10条

  1. List<News> newsList = DataSupport.select("title", "content")  

  2.         .where("commentcount > ?", "0")  

  3.         .order("publishdate desc").limit(10).offset(10)  

  4.         .find(News.class);  

写 SQL 语句查询

Cursor cursor = DataSupport.findBySQL("select * from news where commentcount>?", "0");     


你可能感兴趣的:(轻量级数据库框架LitePal - 查询数据)