英文:
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.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论