简体   繁体   English

没有数据库的简单 pojo 持久化

[英]Simple pojo persistence without database

I have a very simple web project, which need to just persistence some "users", each one just have a few fields("username", "password").我有一个非常简单的 web 项目,它只需要持久化一些“用户”,每个用户只有几个字段(“用户名”,“密码”)。

Now I persistent them into a database, but I think it's too heavy.现在我将它们持久化到数据库中,但我认为它太重了。

I wonder if there are some easy ways to persistent them without a database.我想知道是否有一些简单的方法可以在没有数据库的情况下持久化它们。 It's great just need to save pojos directly.只需要直接保存pojos就太好了。


UPDATE更新

To save them in a file directly(like serialization, properties file) is easy, but not easy with CRUD.将它们直接保存在文件中(如序列化、属性文件)很容易,但使用 CRUD 并不容易。 That means, when I get a specified user, I have to load them, then check the username one by one.这意味着,当我得到一个指定的用户时,我必须加载它们,然后一一检查用户名。 When I update or delete one, I need to load all and save all.当我更新或删除一个时,我需要全部加载并保存所有。

I hope something like db4o , but with a good licence(not GPL nor commercial).我希望像db4o这样的东西,但有一个好的许可证(不是 GPL 也不是商业的)。 The performance is not important here.性能在这里并不重要。

You could use the built-in serialization for Java or have a look at some of the XML serializers, like simple .您可以使用 Java 的内置序列化或查看一些 XML 序列化程序,例如simple .

SQLite might be a suitable alternative to a client/server type database, but use from Java is a little awkward, as some native libs are required. SQLite 可能是客户端/服务器类型数据库的合适替代方案,但使用 Java 有点尴尬,因为需要一些本机库。

Using Properties file is another solution, http://download.oracle.com/javase/tutorial/essential/environment/properties.html But note that you're storing passwords, you might need to encrypt them使用属性文件是另一种解决方案, http://download.oracle.com/javase/tutorial/essential/environment/properties.html但请注意,您可能需要加密它们,存储密码

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM