轻量级数据库框架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");     


  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值