为什么将查找值(组合框值)存储在数据库中而不是将它们放在 html 页面上?

发布于 2024-08-22 22:13:51 字数 66 浏览 15 评论 0原文

支持在数据库中存储组合框值(应用程序的静态查找值(字符串等))与将它们直接存储到 html 页面本身的典型参数是什么?

What are the typical arguments in support of storing combo-box values (static lookup values (strings etc.) for an application) in database vs storing them right into the html page itself ?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(6

撞了怀 2024-08-29 22:13:51

原因是将数据与用户界面分开。

将数据放置在单个位置的目的是使站点的更改、修复和更新更加容易。如果您有 10 个表单,并且每个表单都需要一个状态下拉列表,那么稍后添加一个状态将需要更改 10 个页面上的文本。

即使只有一个下拉装置,分离也使维护变得更加容易。

The reason is to separate your data from the UI.

The purpose of placing data in a single location is to make change, fixes, and updates to a site easier. If you have 10 forms and each needs a state drop down then adding a state later would require changing the text on 10 pages.

Even with just one drop down having the separation makes maintenance easier.

幼儿园老大 2024-08-29 22:13:51

我认为最好的论据是,将这些值保留在数据库中意味着页面上的值始终与数据库中的值同步,或者允许选择哪些值插入数据库。

假设您有一个可以选择的颜色列表。在 HTML 页面上,您允许用户选择“红色”、“绿色”、“蓝色”和“黄色”。数据库反映了这一点。

几周后,您还添加了紫色的功能。因此,您允许用户在 HTML 页面上选择“紫色”,但忽略数据库。某些用户选择“紫色”并尝试将其选择插入数据库,但您会收到外键约束错误,因为“紫色”当前在数据库中不是有效值!

几周后,“黄色”的功能已被删除。这次您记得从数据库中删除黄色,但忘记了 HTML 页面。因此,用户选择“黄色”并尝试将其选择插入数据库,但您会得到相同的外键约束错误!

又一周后,您添加了“粉红色”的功能。这次,您记得将其添加到数据库中,但忘记了 HTML 页面。现在,用户错过了数据库允许的很酷的“粉红色”功能,因为 UI 没有更新!

简单地从数据库中检索可能的值意味着在这种情况下只需要更新数据库。

The best argument, I think, is that keeping those values in the database means that the values on the page are always in sync with what should be in the database, or what values are allowed to be selected for insertion into the database.

Say you have a list of colors you can select. On the HTML page, you allow the user to select 'red', 'green', 'blue', and 'yellow'. The database reflects this.

Several weeks later, you have added the functionality for purple, as well. So you allow the user to select 'purple' on the HTML page, but forget about the database. Some user selects 'purple' and an attempt is made to insert their selection into the database, but you get a foreign key constraint error because 'purple' is not a valid value currently in the database!

Several weeks later, functionality for 'yellow' has been removed. This time you remember to remove yellow from the database, but forget about the HTML page. So a user selects 'yellow' and an attempt is made to insert their selection into the database, but you get the same foreign key constraint error!

Another week later, you add functionality for 'pink'. This time, you remember to add it to the database, but forget about the HTML page. Now, users are missing out on the cool 'pink' functionality that the database allows because the UI was not updated!

Simply retrieving possible values from the database means that only the database needs to be updated in cases like this.

情归归情 2024-08-29 22:13:51

因为查找值可能会随着时间而变化。将一个数据库添加到数据库非常简单,如果您编码正确,它也只会出现在 UI 中。经常查找的值也可以在其他操作中使用,因此将它们卡在 UI 中(尤其是仅在 IIS 提供服务后才“可用”的 UI)会使它们无法访问 - 所以这是一种非常糟糕的做法。

在一个地方定义列表,然后再在多个地方使用它(使更新更容易)也是一种很好的做法,因此数据库是一个好地方。如果数据库不适合或不可用,那么您可以使用另一种机制,例如在程序集或共享模块之一中声明的枚举。

Because look-up values can change over time. It is very simple to add one to a database, then if you have coded things correctly it will also just appear in the UI. Frequently look-up values can also be used in other operations, so having them stuck in the UI (especially one that is only "available" after being served by IIS) makes them unreachable - so it is a Very Bad Practice.

It is also good practice to define the list in one place, before using it in many (makes for easier updates), so the database is a good place for this. If the database is not suitabl or is unavailable, then you could use another mechanism like enumerations declared in one of your assemblies or shared modules.

因为看清所以看轻 2024-08-29 22:13:51

将列表存储在数据库中的另一个原因是列表可能会发生变化。有人会决定更改列表中的现有项目之一,或者他们想要在列表中添加或删除项目。

更改数据库中的数据比重新部署新版本的网页更容易。

Another reason to store the lists in the database is that the list may change. Someone will decide to change one of the existing items in the list, or they will want to add or drop an item in the list.

It is easier to change the data in the database than it is to redeploy a new version of the web page.

极度宠爱 2024-08-29 22:13:51

当您在多个页面上使用这些值时,如果这些值之一发生更改或者添加或删除值,则很难维护列表。

When you use these values on several pages, it is hard to maintain the list if one of these values changes or if a value is added or deleted.

∞琼窗梦回ˉ 2024-08-29 22:13:51
  • 数据和表示分离,因此您可以以多种方式表示数据
  • 当数据仅存储在一个位置时,更容易保持数据最新。
  • 更容易本地化。
  • 如果将元数据添加到数据库,则更容易过滤
  • Separation of data and presentation, so you can present your data in multiple ways
  • Easier to keep data current when it is stored only in one place.
  • Easier localization.
  • Easier filtering, if you add metadata to the db
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文