对于 15 列的表,我们应该编写多少个更新方法

发布于 2024-11-29 04:34:30 字数 445 浏览 4 评论 0原文

我需要 DAO 类在 15 列表上执行 CRUD,我很困惑是否应该编写带有 15 个参数的 1 方法 或带有 1 个参数的 15 方法每个方法的参数或者可能是其他东西。我完成了第一个选择(当然,我很懒:p),但是这个问题(关于标题)让我一整天都搞乱了,GOOGLE对我没有多大帮助,所以我发布这个问题来向各位专业人士请教。为了获得最佳性能,您采取什么解决方案?为了推广它,解决我的问题的最佳实践是什么?
-
Pangea的回答让我想起了我错过的一件事:

我有一个类(MyClass)来表示15列表,实际上,我写了2个方法,第一个有15个参数,第二个有1个参数:MyClass的实例。

第一个方法绝对打破了惯例(1 个方法的参数少于 7 个)。 但我在想,当用户只更改 1 个字段时,如果我们调用第二个方法,我们必须初始化一个新实例。然后...

I got a requirement for a DAO-class to do CRUD on a 15-colunm-table and I'm so confused on whether I should write 1 method with 15 parameter or 15 method with 1 parameter per method or maybe something else. I finished the first choice (of course, I'm lazy :p), but this question (on title) messed me up all day, GOOGLE doesn't help me much so I post this question to ask you pro about it. For the best performance, what is the solution do you make? And to promote it, What is the best practice for my problem?
-
Pangea's answer reminds me of something I missed:

I have a class (MyClass) to represent the 15-column-table, and actually, I wrote 2 methods, 1st one with 15 parameters, and 2nd one with 1 parameter: the instance of MyClass.

The 1st method definitely breaks the convention (less than 7 parameters for 1 method).
But I'm thinking about when a user changes only 1 field, if we call the 2nd method, we must init a new instance. then...

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

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

发布评论

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

评论(2

独孤求败 2024-12-06 04:34:30

在大多数情况下,当从应用程序与数据库通信时,操作的昂贵部分实际上是连接到数据库。

创建 15 个连接 - 甚至一个连接并触发 15 个不同的命令,几乎总是比连接一次并触发一个命令来执行您需要的所有操作要慢。

简而言之 - 在 99.9% 的情况下,对于增删改查操作,一种更新方法会更好......

In most situations, when talking to a database from your application, the expensive part of operation is actually connecting to the database.

Creating 15 connections - or even one connection and firing 15 different commands, is pretty much always gonna be slower than connecting once and firing one command to do everything you need.

In short - one update method will be better in 99.9% of cases for crud operations...

分開簡單 2024-12-06 04:34:30

1 个更新方法怎么样,它采用一个代表表行的简单类。例如 PERSON 表的 Person 类。

How about 1 update method that takes a simple class representing the table's row. for e.g. Person class for a PERSON table.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文