在Spring中将多个数据发送到DB

发布于 2024-09-13 14:26:44 字数 584 浏览 7 评论 0原文

我的 Spring MVC 应用程序中有这种情况。

用户必须选择他/她喜欢的爱好。他可以选择至少一项或多项爱好。我的问题是这样的,如果我需要将爱好列表保存到我的数据库中,我正在考虑发送我的用户选择的爱好列表,以逗号分隔符分隔。

就像这样:篮球、唱歌、跳舞、保龄球

现在,在 JDBC DAO 调用的数据库中的存储过程调用中,我将只解析字符串列表,然后一一执行插入语句?

我也可以使用

Begin Try
 Begin Tran
  //perform series of inserts here
 Commit Tran
End Try
Begin Catch
 Rollback Tran
End Catch

我认为这将限制从 Spring JDBC 到数据库的事务量。如果第二次或第三次插入失败,这也可以防止我的事务不完整。

我听说过 Spring 事务管理功能,但我真的还没有机会研究它,并且由于时间限制,我坚持到目前为止我所知道的。 Spring有这么多模块,我没有时间全部研究它们。

你认为,以我目前对 Spring 的了解,我的想法可以吗?

I have this scenario in my Spring MVC Apps.

User has to choose what hobbies he/she likes. He can choose at least one or many hobbies. My problem is this, If I need to save the list of hobbies into my DB, I am thinking of sending the list of hobbies that my user has chosen, delimited by a comma separator.

It's like this: Basketball, Singing, Dancing, Bowling

Now, In my stored procedure call in my DB called by JDBC DAO, I will just parse the List of string and then perform Insert Statements one by one?

I can use also the

Begin Try
 Begin Tran
  //perform series of inserts here
 Commit Tran
End Try
Begin Catch
 Rollback Tran
End Catch

I am thinking that this will limit the amount of transaction from my Spring JDBC to DB. This would guard me also from having incomplete transaction should the second or third insert fails.

I have heard about Spring Transaction Management feature but I really haven't had the chance to study it yet and I am sticking to what I know so far because of time constraints. Spring has so many modules and I do not have the time to study them all.

Do you think, given my current knowledge of Spring, my idea is OK?

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

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

发布评论

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

评论(1

初吻给了烟 2024-09-20 14:26:44

在存储过程中管理事务的想法相当老式,但完全有效。

Spring提供了JDBC和JTA事务管理,这有助于应用程序级事务管理。如果您想在存储过程中管理事务,那么您不会对 Spring 的事务内容有太多用处,因此您可以安全地忽略它。

The idea of managing your transactions inside a stored procedure is quite old-fashioned, but perfectly valid.

Spring provides JDBC and JTA transaction management, which helps with application-level transaction management. If you want to manage your transactions in the stored procedure instead, then you're not going to have much use for Spring's transaction stuff, so you can safely ignore it.

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