gpt4 book ai didi

android - 在 DBFLow 中排序

转载 作者:太空宇宙 更新时间:2023-11-03 13:50:01 24 4
gpt4 key购买 nike

我正在尝试在我的 Android 项目中实现 DBFlow。我已经能够创建一个表并向其中添加行和列。我有两列,ID 和 Names。现在我想从表中检索名称并按 ID 降序排列。我在 Github DBFlow 页面中找到了这个示例语法

SQLite.select()
.from(table)
.where()
.orderBy(Customer_Table.customer_id, true)
.queryList();

SQLite.select()
.from(table)
.where()
.orderBy(Customer_Table.customer_id, true)
.orderBy(Customer_Table.name, false)
.queryList();

但我无法理解“Customer_Table.customer_id”在该代码中的含义。当我尝试放置方法 orderBy() 时,Android Studio 建议将 (NameAlias nameAlias, boolean) 作为参数。如何将 NameAlias 添加到我的表中?有人可以帮我解决这个问题吗?

最佳答案

当您在项目中实现 DbFlow 时,它会自动为您使用 @Table 注释进行注释的每个表模型构建一个表类。

即,如果您有一个名称为 Customer 的表,则相应的类将为 Customer_Table,如果您的表为 User,则相应的类将为 User_Table。

让它成为您的客户表:

@Table
public class Customer extends BaseModel {
@Column
String customer_name;
}

如果你想在 Customer 表中使用客户名称对你的结果进行排序,那么可以这样使用,

SQLite.select()
.from(table)
.where()
.orderBy(Customer_Table.customer_name, true)
.queryList();

关于android - 在 DBFLow 中排序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36267704/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com