简体   繁体   中英

Save generic object in database

My model is like:

public class MyModel{
    private String mId;
    private String mName;
    T mAnObject;
}

How can I store T object in database .

如果您需要保存特定的属性,只要做到这一点,否则你可以把它序列化到JSON ,作为一个选项(如证明这里 )。

Example: Object myObj has three properties: String title, String subtitle, String text

1 - You can save them as separate database rows and then when you read from the database you recombine them to create your Object.

2 - You can also use Json to save the properties, this way you only need to store a single String in the database and when you read from the database convert the Json String to your Object.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM