android - 带有 ID 的房间查询返回 null
问题描述
我正在为我的数据库使用房间持久性库。我的一个查询返回 null,我不明白为什么:
实体:
@Entity
public class Item{
@PrimaryKey (autoGenerate = true)
@ColumnInfo (name = "I_ID")
private final int iId;
@ColumnInfo (name = "I_Name")
private final String iName;
public int getIId() {
return iId;
}
public String getIName() {
return iName;
}
public Item(int iId, String iName) {
this.iId = iId;
this.iName = iName;
}
}
道:
@Dao
public interface ItemDao {
@Query("SELECT * FROM Item WHERE I_ID = :iId")
Item getItemById(int iId);
}
此查询显示警告:Return value of the method is never used
。它总是返回 null,即使我确定数据库中存在具有给定 ID 的项目。有人可以帮助我吗?
解决方案
我发现尝试这样使用:
@Dao
public interface ItemDao {
@Query("SELECT * FROM item WHERE I_ID = :iId")
List<Item> getItemById(int iId);
}
推荐阅读
- mysql - 对于具有单词类型(名词,动词......)的语言词典,最好的方法是什么?
- c# - c#如果表处于关系中,则在getrequest中返回表数据会出错
- c++ - 使用 shared_ptr 和 unique_ptr 指向数组时的区别?
- firebase - Flutter Firebase BLoC 模式
- python - 从 CSV 文件中提取最后一行并将其放入另一个文件中,并在 Python 中使用文件名
- reactjs - 如何更改 Material-UI 表格的悬停颜色?
- node.js - 如何使用其他字段验证来停止 Multer 中的文件上传?
- ab-testing - 全站谷歌优化重定向测试
- angular - 带有 URL 前缀的 Angular 模块(路由)
- c - LKM linux_dirent 实现