简体   繁体   English

如何为类似的请求建模数据?

[英]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.

相关问题 如何动态地将模型类设置为翻新请求? - How to set dynamically model class to Retrofit requests? 如何在动态模型类中使用模型值来改进请求? - How to use model values in dynamically model class to Retrofit requests? 改造中按顺序多个相似的请求 - Multiple similar requests in sequence in retrofit 设计Web服务的最佳方法,该服务必须将请求中的数据存储在列表或类似结构中 - Best way to design web service, which have to store data from requests in list or similar structure 数据集成问题-如何集成相似实体 - Data integration problem - How to integrate similar entities 如何在列表之间找到相似的数据? - How to find the similar data in between to list? 如何用不同的数据表示相似的对象 - How to represent similar objects with different data 如何将数据请求与数据更新过程同步? - How to synchronize requests for data with data update process? 将 Java 数据 Class 转换为前端的字段数组/元数据(类似于 Swagger 数据模型/模式)? - Convert Java Data Class to Array of Fields/Metadata for frontend (Similar to Swagger Data Model/Schema)? BufferedInputStream 如何从 OS 请求数据块 - How BufferedInputStream requests data in chunks from OS
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM