使用JSON客户端时正常化VS非规范化与Java / RDBMS栈化与、客户端、JSON、VS

由网友(两逗比相遇便胜过人间无数)分享简介:我有一个角JS JSON客户端与JAVA / MySQL的堆栈接口。由于MySQL是一个RDBMS,我的所有数据都将归(前三种形式当然)。我的问题可以用下面的例子来说明。我有一个实例对象,并通过服务器返回一个User对象。 示例 - [{用户名:1​​,........},{用户名:2,...},{用户名:3,......

我有一个角JS JSON客户端与JAVA / MySQL的堆栈接口。由于MySQL是一个RDBMS,我的所有数据都将归(前三种形式当然)。

我的问题可以用下面的例子来说明。

我有一个实例对象,并通过服务器返回一个User对象。

 示例 -  [{用户名:1​​,........},{用户名:2,...},{用户名:3,...}];用户 -  [{用户id  -  1,的firstName  - 约翰,lastName的 - 李四,..},{用户id  -  2,的firstName  - 简,lastName的 - 李四,..},{...} ...] 

当我期待通过使用角例如,在example_entry并显示示例集合元素的例子集合,我只有用户id一应俱全。但是,如果我想显示名字和姓氏,我不能,因为它是在一个不同的用户征收做。我必须写一个辅助角控制器/服务方法,从用户收集得到的名字,姓氏和实例集合对象比分扳成了。

要避免这个问题,我可以去规范化的Java Ojbects并发出准备使用JSON这样的..

 示例 -  [{用户名:1​​,的firstName  - 约翰,lastName的 - 李四,........},{用户id  -  2,的firstName  - 简,lastName的 - 李四,...},{用户名:3,...}]; 
IDEA使用GsonFormat完成JSON和JavaBean之间的转换

但是,这是好/坏/可怕吗?因为现在我的Java域对象有名字,姓氏重复的实例对象,也是用户对象。任何建议在哪条路线更好?

 德规范和有准备使用JSON保留数据标准化为避免重复,写上客户端转换器方法需要 

解决方案

下面是我对这个。当涉及到显示房源的数据,我并不担心领域模型类。对我来说,返回的数据应该与尽可能多的用户界面的显示要求。这里的目的是为了显示数据,用户并没有太多的决策是这样的屏幕来完成。

但是,如果数据需要修改更新,人们需要更加小心的是什么派,而实体于更新参加。保持数据一致成为优先和去正常化可能不是正确的适合在这种情况下。

I have a Angular JS JSON client interfacing with a JAVA/MySQL stack. As MySQL is an RDBMS, all my data is normalized (first three forms of course).

My question can be illustrated with the following example.

I have an Example object and a User object returned by the server.

Example - [{
userId:1,
...
...
..
},
{
userId:2,
...},
{
userId:3,
...}];

User - [
{
userId - 1,
firstName - "John",
lastName - "Doe",
..
},
{
userId - 2,
firstName - "Jane",
lastName - "Doe",
..
}, {...}...
]

When I look through the Example collection using Angular "example_entry in example" and display the Example collection elements, I only have the userId readily available. But if I want to display the firstName and lastName, I can't do it as it's in a different "User" collection. I have to write a helper Angular controller/service method to get the firstName, lastName from User collection and tie it with Example collection objects.

To avoid this problem, I could De-Normalize the Java Ojbects and send out ready to use JSON like this..

Example - [{
userId:1,
firstName - "John",
lastName - "Doe",
...
...
..
},
{
userId - 2,
firstName - "Jane",
lastName - "Doe",
...},
{
userId:3,
...}];

But is this good/bad/terrible? Because now my Java Domain Objects have firstName, LastName duplicated in the Example Object and also the User Object. Any advise on which route is better?

De-Normalize and have ready to use JSON
Keep Data Normalized to avoid duplication and write converter methods on the Client as needed

解决方案

Here is my take on this. When it comes to displayinglisting data I am not worried about the Domain modelclasses. For me the data returned should match as much as possible the UI display requirements. Here the intent is to show data to user and not much decision making is done of such screens.

But if data needs to be changedupdated one needs to be more careful of what is send, which entities take part in the updation. Keeping data consistent becomes priority and de-normalization may not be right fit in such cases.

阅读全文

相关推荐

最新文章