[英]How to model data for similar requests?
I have an issue, I'm not sure how should I model the data from the backend when I have some really similar views on the front, particularly some forms. 我有一个问题,当我在正面有一些非常相似的视图(尤其是某些形式)时,不确定如何从后端对数据建模。
For example in one of them the user sends an id for a seller and a product code, but in another one the inputs ask for an id seller, a product code, and two dates. 例如,在其中一个中,用户发送了卖方的ID和产品代码,但在另一个中,输入则要求有ID卖方,产品代码和两个日期。
This is silly case probable but there are some others too, and I didn't know if I was supposed to duplicate data on the model or what. 这种情况很可能很愚蠢,但是还有其他一些情况,我不知道是否应该在模型上复制数据或什么。
Is there some design pattern one should follow or some convention? 是否有一些应该遵循的设计模式或某种惯例? If it helps, I'm
trying to use
using Angular on the front and java for backend. 如果有帮助,我
尝试
在前端使用Angular,在后端使用Java。
On back-end side, we usually have a controller with the endpoint which takes a model that comprises all the possible fields. 在后端,我们通常有一个带有端点的控制器,该控制器采用包含所有可能字段的模型。
class Model { Object id, code, date1, date2; }
It's up to the controller to determine which service (or which method of the service) it should delegate work to: 由控制器确定应将工作委派给哪个服务(或该服务的哪种方法):
{id, code} -> service1
{id, code, date1, date2} -> service2
Another approach suggests including optional parameters. 另一种方法建议包括可选参数。 In your case, they are two dates:
您的情况是两个日期:
class Model { Object id, code; }
{model*} -> service1
{model*, date1, date2} -> service2
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.