Eli*_*Eli 3 eclipse orm android ormlite
在文档中提到以下内容:
Account account = accountDao.queryForId("John Smith");
if (account == null) {
// the name "John Smith" does not match any rows
}
Run Code Online (Sandbox Code Playgroud)
但在Eclipse(android)中我只看到传递整数作为参数的选项?任何帮助?
Gra*_*ray 10
该Dao对象使用泛型执行ID的类型与实体相关联.如果你只看到传递整数的选项dao.queryForId(...)那么你可能错误地定义了dao:
Dao<Account, Integer> accountDao = getDao(Account.class);
Run Code Online (Sandbox Code Playgroud)
第一个泛型参数指定实体的类型,第二个泛型参数指定该实体中的ID字段的类型.随着Integer,你会打电话accountDao.queryForId(Integer).
正如@Tomas所提到的,你需要用以下内容定义你的DOA:
Dao<Account, String> accountDao = getDao(Account.class);
Run Code Online (Sandbox Code Playgroud)
然后你可以Account通过Stringid 查询:
Account account = accountDao.queryForId("John Smith");
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1786 次 |
| 最近记录: |