• Android SugarORM(3)


    Android Sugar ORM (3)

    Android Sugar ORM 查询

    我们在此之前介绍了一些关于Sugar ORM的简单操作, 现在我们就查询来具体说一下

    Sugar ORM中的find()方法

    我们在此介绍了一个方法: findAll(), 它返回的是Iterator<T>类型, 就是我们所说的迭代器, 有很多方便的地方, 也有很多不方便的地方, 当然还有findById()方法, 根据id来找我们的数据, 相对来说也是不够用的, 这时候就需要我们现在所讲的find()方法了

    find()方法的使用方式是向该方法中传递where子句和参数。它遵循与SQLite数据库查询方法相同的约定。

    Note.find(Note.class, "name = ? and title = ?", "Satya", "title1");
    

    如果你有其他条件,如按分组、按顺序排序或限制,则可以在域实体上使用以下方法:

    Entity.find(Class<T> type, String whereClause, String[] whereArgs, String groupBy, String orderBy, String limit)
    

    当然你也可以自定义查询语句, 也就是使用原生的SQL语句来操作

    // Could execute other raw queries too here..
    Note.executeQuery("VACUUM");
    
    // for finders using raw query.
    List<Note> notes = Note.findWithQuery(Note.class, "Select * from Note where name = ?", "satya");
    

    使用查询生成器方法

    Select.from(TestRecord.class)
            .where(Condition
            .prop("test")
            .eq("satya"),
        Condition.prop("prop")
            .eq(2))
            .list();
    
  • 相关阅读:
    poj_3923Ugly Windows
    背包问题九讲笔记_01背包
    素数环
    全排列的STL实现
    [1424] 金克拉与贪吃蛇的故事
    hdoj_1548A strange lift
    iBATIS缓存配置详解
    jQuery的一些特性和用法:
    当iBATIS出项某个列不存在的问题
    当iBATIS出项某个列不存在的问题
  • 原文地址:https://www.cnblogs.com/donpangpang/p/12755633.html
Copyright © 2020-2023  润新知