【问题标题】:Implementing a SQLite Database with List<String> as Column type using ORMLite使用 ORMLite 实现将 List<String> 作为列类型的 SQLite 数据库
【发布时间】:2014-11-08 14:36:25
【问题描述】:

我有一个需求,我需要在数据库的列中存储一个列表。序列化列表可能是一种选择,但我不确定它是否正确。

另外,我想避免创建另一个表来存储列表元素和对原始表行的引用。

我正在使用ORMLite 进行数据库操作。

【问题讨论】:

    标签: android ormlite


    【解决方案1】:

    是国外收藏的概念。

    您需要创建一个包装字符串的实体。看起来像:

     @DatabaseTable
     public class Student {
         @DatabaseField(generatedId = true)
         print int id;
         @DatabaseField
         private String fname;
         @DatabaseField
         private String lname;
         @DatabaseField(foreign = true)
         private Address address;
    
     }
    Then your Address class would have a ForeignCollection of these Student.
    
     @DatabaseTable
     public class Address {
         @DatabaseField(generatedId = true)
         print int id;
         @ForeignCollectionField()
         private ForeignCollection<Student> student;
     }
    

    也可以参考这个link,希望对你有帮助。

    【讨论】:

      猜你喜欢
      • 2019-04-11
      • 1970-01-01
      • 2013-05-12
      • 1970-01-01
      • 2017-03-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-09-27
      相关资源
      最近更新 更多