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

时间不是很充裕:转载了别人的一篇帖子,能够拿来急用,也可收藏。
地址:http://blog.csdn.net/pkuyjxu/article/details/47871807
第二次用LitePal数据库框架,给我的感觉是非常简便的ORM框架:1)特别是配置。2)api方法使用非常简单 性能对比与其它的框架可能若一点点【可自行查阅资料】

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);  

LIMIT 所要取的记录数目(以基准点为参考点) OFFSET 基准点

List 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");    
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

ItJavawfc

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值