[英]Storing ArrayList object data in mySQL Database
I am creating a web application that has a User object and each User object has an ArrayList of objects (Food) that need to be stored into a table in a mySQL database. 我正在创建一个具有User对象的Web应用程序,每个User对象都有一个对象的ArrayList(Food),需要存储到mySQL数据库的表中。 I want to store the entire ArrayList into a single column. 我想将整个ArrayList存储到一个列中。 Would it be better to store it as a Json? 将它存储为Json会更好吗? Or should I just create a table for each User that stores the individual items of the ArrayList? 或者我应该为每个存储ArrayList的各个项的用户创建一个表? The only problem I have is that the data would edited quite frequently. 我唯一的问题是数据会经常编辑。
EDIT: I have tables for both Users and Food. 编辑:我有用户和食物的表。 The idea is that Users add from the Foods from the Food table to their ArrayList and then I want to store that ArrayList in something. 想法是用户从Food表中的Foods添加到他们的ArrayList,然后我想将ArrayList存储在某个东西中。
public class User{
private int id;
private String username;
private List<Food> FoodList = new ArrayList<Food>();
}
public class Food{
private int id;
private String name;
private double protein;
private int calories;
...
}
(Welcome to SO, btw!) (欢迎来到SO,顺便问一下!)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.