android - List<String> 作为@ForeignCollectionField ormlite

标签 android ormlite

我的模型类中有

List<String> _photo_array;

因为我可以在 String 类上添加注释,是否可以使用 ormLite 来持久化它?

最佳答案

since I can put anotation on String Class is it a way to persist it using ormLite?

您将必须创建一个包装 String 的实体。像这样的东西:

 @DatabaseTable
 public class Photo {
     @DatabaseField(generatedId = true)
     private int id;
     @DatabaseField
     private String photo;
     @DatabaseField(foreign = true)
     private Model model;
 }

然后您的模型类将有这些照片的 ForeignCollection

 @DatabaseTable
 public class Model {
     @DatabaseField(generatedId = true)
     private int id;
     @ForeignCollectionField()
     private ForeignCollection<Photo> photos;
 }

参见 foreign collection example .

关于android - List<String> 作为@ForeignCollectionField ormlite,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20349587/

相关文章:

android - 使用Maven apklib时出现编译错误

android - 位图大小超出 VM 预算 java.lang.OutOfMemoryError : bitmap size exceeds VM budget

java - 无法禁用 ORMLites 日志记录

android-fragments - 将 ORMLite 与 Fragment 一起使用

android - 带报价的 ORMLite 查询,Android

java - ORMLITE 支持 SQL EXISTS 吗?

java - 尝试在空对象引用上调用虚拟方法 'android.view.SurfaceHolder android.view.SurfaceView.getHolder()'

android - 不同应用中的相同 SKU (Google Play)

java.lang.NullPointerException : storage == null 异常

java - 在 ORMLite 中为 ApplicationSettings 存储多个 ArrayLists 的最佳方式