在ORMLite中为ApplicationSettings存储几个ArrayLists的最佳方法 [英] Best way to store several ArrayLists in ORMLite for ApplicationSettings
问题描述
现在我试图在 ORMLite
的帮助下将应用程序的设置持久化到我的 DB
。
Right now I am trying to persist the Settings of an Application to my DB
with the help of ORMLite
.
我的设置包括不同的 String []
或 ArrayList< String& code>或者也许
Map
实际上只是一堆 Strings
。所以我的问题是,我应该使用什么数据类型这种情况和可选的,也许你也可以提供一个小代码示例
。
Well my settings consist of different String[]
or ArrayList<String>
or maybe a Map
actually just a bunch of Strings
. So my question is, what datatype should I use for such a scenario and optional maybe you could also provide me a small code example
.
现在我尝试了不同的东西,但我从来没有对解决方案感到满意。我尝试的东西像:
Right now I tried different things, but I never was happy with the solution. I tried stuff like:
private HashMap<String, ArrayList<String>> configurationMap;
private String[] stringArr1;
private String[] stringArr2;
private ArrayList<String> arrList1;
但是当设置 DB数据类型
我总是认为,我不想要一个额外的表来存储数据或有一个地图序列化到数据库的...。
But when it comes to setup the DB Datatypes
I always think, "I don't want an extra table to store the data" or "having a map serialized to the DB sucks...".
也许任何人都有一个想法如何以一个很好的和方便的方式解决这个问题。
Maybe anybody has an idea how to solve this in a nice and convenient way?
推荐答案
对于arrayList你可以简单地做以下:
For the arrayList you can simply do the following :
public class YourClass{
@GeneratedId
private int id;
@ForeignCollectionField
private Collection<MyString> bunchOfStrings = new ArrayList<MyString>();
...
}
在MyString类中,
In the MyString class you have the following :
public class MyString{
@DatabaseField(canBeNull = true, foreign = true)
private YourClass yourClass;
@DatabaseField
private String text;
....
}
这是全部
这篇关于在ORMLite中为ApplicationSettings存储几个ArrayLists的最佳方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!