如何在Java Web应用程序中存储持久性数据?

huangapple go评论66阅读模式
英文:

How should I store persistent data in java web app?

问题

我遇到了一些关于我的Java Web项目的问题。我的意思是,这个项目类似于课程管理系统。实际上,这是我的第一个真正的项目。所以,我的问题是我不知道如何存储教师上传给他的学生的与特定课程相关联的文件。我考虑过使用数据库(我正在使用MySQL与Hibernate来持久化教师、学生和课程对象),但我不确定如何做,因为将文件与适当的课程关联的最简单方式是使用它们的某个列表,我不知道是否可能(因为这些文件将需要Blob)。所以,如果可能的话,你能帮我找到一种实现的方法吗?如果不可能,我该怎么办?

英文:

I'm having some problems with my java web project. I mean, this project is something like course managing system. I fact, it's my first real project. And so, my problem is that I don't know how to store files (associated with specific course) that teacher uploads for his students. I thought about using a database (I'm using MySQL with Hibernate for persisting Teacher, Student and Course objects), but I'm not sure how to do it because the easiest way to link the files with appropriate Course would be with some List of them and I don't know if that's possible (because these files would need Blob). So, if it is, can you help me find a way to do it? And if it isn't, what should I do?

答案1

得分: 0

在数据库中存储文件并不是一个明智的做法,一旦记录数量开始增加,整个系统的速度就会变慢。
更好的方法是:

  • 创建一个用于下载已上传文件的服务,将其存储在现有目录中,并返回相应的UUID(您可以使用时间戳和文件名来生成UUID)。
  • 将UUID存储在数据库中。
英文:

Storing files in a database is not a smart thing to do and will slow down the entire system once the number of records start growing.
Better approach will be something like:

  • Create a service for downloading uploaded file in an existing directory and returning a UUID for the same (You can use the timestamp and name of the file for this).
  • Store the UUID in the database.

huangapple
  • 本文由 发表于 2020年8月9日 06:22:53
  • 转载请务必保留本文链接:https://go.coder-hub.com/63320762.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定