GreenDao进阶篇 GreenDao分页查询

GreenDao进阶篇
GreenDao分页查询

/**
 * 分页条件查询实体集合
 *
 * @param where
 * @param conditions
 * @param properties 倒序
 * @param offset
 * @param limit
 * @return
 */
public List<SMessage> querySMessage(String where, String[] conditions, Property properties, int offset, int limit) {
    QueryBuilder<SMessage> qb = mManager.getDaoSession().queryBuilder(SMessage.class)
            .orderDesc(properties)
            .where(new WhereCondition.StringCondition(where, conditions))
            .offset(offset * limit)
            .limit(limit);
    return qb.list();
}

示例:

//条件查询示例
daoUtils.querySMessage("USER_ID = ? AND DEVICE_TYPE = ?", 
                        new String[]{userId, typeId}, 
                        SMessageDao.Properties.Tailtime, 
                        offset, 
                        MessageFragment.REQUEST_NUM);