尝试使用 ORMLite 来保持课程Goods
时,我不知道如何在componentList
保留public class Goods extends Object implements Serializable
{
private static final long serialVersionUID = -7560219283718464481L;
...
public ArrayList<String> componentList;
public String getComponentList(){
return componentList;
}
public void setComponentList(ArrayList<String> componentList){
this.componentList = componentList;
}
...
}
。我发现了一个类似的问题Persisting a Collection class with ORMLite in android,但似乎没有找到解决问题的方法。
{{1}}
答案 0 :(得分:2)
我发现了一个类似的问题在android中使用ORMLite保持Collection类,但它似乎没有指明解决问题的方法。
不幸的是,它是ORMLite存储相关项目集合的唯一方式。在您的情况下,您需要一个Component
类,其类似于:
public class Component { @DatabaseField(foreign = true) 私人物品; ...
然后你的Goods
课程将是:
public class Goods {
@ForeignCollectionField
private Collection<Component> components;
...
要将组件分配到Goods
表格中的条目,您需要创建Component
条目并设置goods
字段和dao.create(...)
字段。
查看可能提供更多信息的foreign-collection docs。 引用他们的话:
外国集合允许您在帐户表上添加订单集合。每当查询返回或由DAO刷新Account对象时,都会对订单表进行单独查询,并在帐户上设置订单集合。集合中的所有订单都具有与帐户匹配的相应外来对象。例如:
public class Account {
…
@ForeignCollectionField(eager = false)
ForeignCollection<Order> orders;
…
}
在上面的示例中,@ ForeignCollectionField注释标记订单字段是与帐户匹配的订单的集合。订单的字段类型必须是ForeignCollection或Collection - 不支持其他集合,因为它们更重,有许多方法需要支持。