public static synchronized <T> T find(java.lang.Class<T> modelClass, long id, boolean isEager)
查询单条数据.查询第一条数据
-
News news = DataSupport.find(News.class, 1);
-
News firstNews = DataSupport.findFirst(News.class);
查询多条数据
-
List<News> newsList = DataSupport.findAll(News.class, 1, 3, 5, 7);
-
long[] ids = new long[] { 1, 3, 5, 7 };
-
List<News> newsList = DataSupport.findAll(News.class, ids);
-
List<News> allNews = DataSupport.findAll(News.class);
指定条件查询
-
List<News> newsList = DataSupport.where("commentcount > ?", "0").find(News.class);
//查询news表中所有评论数大于零的新闻
只需要指定的字段
-
List<News> newsList = DataSupport.select("title", "content")
-
.where("commentcount > ?", "0").find(News.class);
并且根据指定字段排序
-
List<News> newsList = DataSupport.select("title", "content")
-
.where("commentcount > ?", "0")
-
.order("publishdate desc").find(News.class);
只需要前10条数据
-
List<News> newsList = DataSupport.select("title", "content")
-
.where("commentcount > ?", "0")
-
.order("publishdate desc").limit(10).find(News.class);
需要10~20条的数据 ,offset:偏移量. 传入10 就是10以后的10条
-
List<News> newsList = DataSupport.select("title", "content")
-
.where("commentcount > ?", "0")
-
.order("publishdate desc").limit(10).offset(10)
-
.find(News.class);
写 SQL 语句查询
Cursor cursor = DataSupport.findBySQL("select * from news where commentcount>?", "0");