简体   繁体   English

从客户端发送GSON字符串服务器设计问题的java

[英]Sending GSON string from client to server Design issue in java

I am building an application which allows restaurant guests to order food and send to server. 我正在构建一个允许餐厅客人点餐并发送到服务器的应用程序。

What i have considered is to 我所考虑的是

1) create a class Order.java class 1)创建一个类Order.java类

public class Order
{

private Intger  tableId;
private Integer restaurantId;
private Integer foodId;
private Integer foodQuantity;

getter and setters
}

2) This class object will be populated with guests order and an ArrayList of objects of the class will be sent to server as Gson String. 2)该类对象将用来宾顺序填充,并且该类对象的ArrayList将作为Gson String发送到服务器。

Now if an order consist of some 7 items, Then the arraylist will have 7 objects, but tableId and restaurantId will be same 7 times. 现在,如果一个订单包含大约7个项目,则arraylist将具有7个对象,但是tableId和restaurantId将是7次相同。

can you suggest a better design where in I can associate restaurantId and tableId with the entire arraylist. 您可以建议一个更好的设计,在其中我可以将restaurantId和tableId与整个arraylist相关联。

Thanks. 谢谢。

There is no right solution, it would depend on your needs, one possible solution would be something like: 没有正确的解决方案,这取决于您的需求,一种可能的解决方案是:

public class Order {

    private int tableId;
    private int restaurant;
    private List<OrderItem> items;

    // setters and getters

}

public class OrderItem {

    private int itemId; // foodId
    private int quatity; // foodQuantity

    // setters and getters

}

But if you were in a situation that the information comes not normalized, like you suggested (in which tableId is repeated for every single food ordered), I would consider to implement a normalization process that will return a structure with the classes I draft above. 但是,如果您遇到信息未标准化的情况(如您建议的那样(对于订购的每种食品都重复使用tableId)),我将考虑实施一个标准化过程,该过程将返回一个结构与我在上面草拟的类。 But if you are implementing it, please consider to make it as normalized as possible. 但是,如果要实现它,请考虑使其尽可能标准化。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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