直接问题:
设计用于存储页面上配置的 url 的数据库表的最佳实践是什么。
我们的用例:
我们进行了设计讨论,但无法得出正确设计的结论。我们正在编写一个在表格中嵌入 URL 的页面。所以页面看起来像
....content(some text)...
a |b |c |d
text |url |url |url
text |url |url |url
text |url |url |url
....content(some text)...
这个想法是在数据库中配置这些 url,这样每次 url 更改时 url 更改都不需要部署。
EDIT> a,b,c,d
是表头。虽然部分下的内容a
将是普通文本,但其下的内容b,c,d
将是超链接。
考虑到这一切,应该为这个结构设计什么表。我们考虑了两种模式:
(a,b(url),c(url),d(url)) #dependent on table design. advantage: written code would
#be very simple and would not be dependent on the number
#of entries in the table.(a simple for loop would
#suffice for presentation logic). Disadvantage: if table
#changes in future, this table is doomed.
#EDIT>a,b,c,d are place holders to represent that content
#represent the headers of table.
(id, url) #advantage: Generic enough to encompass any url.
#disadvantage: This would require presentation layer changes in
#case of new addition of new row.
#EDIT>id is just a number to identify this url and would be used to
#refer while identifying this from presentation layer.
我们无法断定哪一个更好,因为每个都有自己的权衡(直到我们错过了一些东西)。或者这些都不好。
我们使用 NoSql Store 和 Jsp 来编写前端(演示)逻辑。
编辑>以下可能是表可能发生的更改类型:
- 添加新行(频繁)。
- 删除现有行(频繁)。
- 列的顺序可以改变(但很少见)。
- 列数变化(非常罕见,认为从未发生过但可能发生)。
- 底层 URL 的更改(两种设计都支持,所以不重要)。
这里主要关注的是维护开销(在演示和后端角度),这将由所考虑的任何一种设计引起。
编辑2>
所以这个项目只是为已经存在的服务编写前端。我们不必过多处理所谓的应用程序状态。但是在某个网页上,有几个 URL(嵌入在我提到的表中)并且业务要求不是每次有人提出更改请求时都部署(这段代码)(例如更改现有 url,即最常见的变化类型)。因此,所有关于 URL 的信息都将被移动到数据库中,并在网页加载时查询(或者可能是预加载的,这样我们就不会破坏页面的性能)。现在这个讨论是关于为此用途设计一个合适的表。