简体   繁体   English

保存在Java桌面应用程序应用程序和网站上使用的个人用户设置的最佳方法

[英]Best way to save personal user settings who are used on java desktop application app and website

I'm creating an application where i store all the users settings into a MySQL server. 我正在创建一个应用程序,其中将所有用户设置存储到MySQL服务器中。 But now i got like something when tableOption3 = id25 then the users theme is red. 但是现在,当tableOption3 = id25时,我得到了类似的东西,那么用户主题为红色。 I already got 5 such tables. 我已经有5张这样的桌子。 And it going to get alot bigger. 而且它会变得更大。 The user can use an mobile application that saves the personal settings for the website and java application and visa versa. 用户可以使用移动应用程序保存网站和Java应用程序的个人设置,反之亦然。

Do I have other options? 我还有其他选择吗? And I keep wondering what happens if there would be 100 personal option to be loaded. 我一直想知道如果要加载100个个人选项会发生什么情况。 Would the user notice this in loading speed. 用户是否会在加载速度中注意到这一点。

You have to save these personal user settings somewhere and you will always want to use some sort of datastore, like: SQL databases , NOSQL , flat files. 您必须将这些个人用户设置保存在某处,并且您将始终想要使用某种数据存储,例如: SQL databasesNOSQL ,平面文件。
I think that SQL databases are usually way to go, and having more then 100 personal options shouldn't degrade performance too much. 我认为SQL数据库通常是可行的方法,拥有100个以上的个人选项应该不会降低性能。

But my advice will be to avoid having multiple tables. 但是我的建议是避免有多个表。 You can achieve desired effect, with all properties stored for all users, by having just one table , ie: just one table ,即可为所有用户存储所有属性,从而达到预期的效果,即:

 USER_ID | PROPERTY | PROPERTY_VALUE
 1       | COLOR    | RED
 2       | COLOR    | BLUE
 1       | FONT_SIZE| 12
 2       | FONT_SIZE| 14
etc

If you're looking for a drop-in solution for Java you can try jsup , which is a java library to store and fetch simple user preferences in SQL databases. 如果您正在寻找Java的嵌入式解决方案,可以尝试jsup ,它是一个Java库,用于在SQL数据库中存储和获取简单的用户首选项。

I am the author of jsup and write a lot of small applications/tools. 我是jsup的作者,并编写了许多小型应用程序/工具。 I have often found the need to support user preferences and didn't find a suitable library that worked with different SQL databases, so I went ahead and created jsup. 我经常发现需要支持用户首选项,并且找不到适合于不同SQL数据库的合适的库,因此我继续创建jsup。

It works with a variety of common SQL database types and is simple to get started with: 它可以与多种常见的SQL数据库类型一起使用,并且很容易上手:

Injector injector = Guice.createInjector(
    new AbstractModule() {
      @Override
      protected void configure() {
        HikariConfig config = new HikariConfig();
        config.setJdbcUrl("jdbc:h2:mem:testdb");
        HikariDataSource dataSource = new HikariDataSource(config);

        // Be sure to specify the correct dialect.
        bind(Key.get(SQLDialect.class, UserPreferencesModule.UserPreferences.class)).toInstance(SQLDialect.H2);
        bind(Key.get(DataSource.class, UserPreferencesModule.UserPreferences.class)).toInstance(dataSource);
      }
    },
    new UserPreferencesModule());
UserPreferencesDb userPreferencesDb = injector.getInstance(UserPreferencesDb.class);
UserPreferencesAnalytics userPreferencesAnalytics = injector.getInstance(UserPreferencesAnalytics.class);

userPreferencesDb.setString("some-user", "ui", "theme", "default");
userPreferencesDb.setString("some-user", "ui", "display.timestamp.timezone", "UTC");
userPreferencesDb.addToSet("some-user", "app", "favorite.projects", ImmutableSet.of("prj1", "prj2"));
userPreferencesDb.setBoolean("some-user", "app", "email.on.failure", true);

System.out.println(userPreferencesDb.getString("some-user", "ui", "theme"));
System.out.println(userPreferencesDb.getString("some-user", "ui", "display.timestamp.timezone"));
System.out.println(userPreferencesDb.getSet("some-user", "app", "favorite.projects"));
System.out.println(userPreferencesDb.getBoolean("some-user", "app", "email.on.failure"));

System.out.println(userPreferencesAnalytics.getStringCategories());
System.out.println(userPreferencesAnalytics.getBooleanPreferencesByUser("app", "email.on.failure"));

In addition to a DB interface to store and fetch preferences, there is an analytics interface to get stats or make integration with other tools easier. 除了用于存储和获取首选项的数据库界面外,还有一个分析界面,可用于获取统计信息或简化与其他工具的集成。

There are examples and more documentation on the GitHub page. GitHub页面上有示例和更多文档。 If there are things you'd like added please open a ticket. 如果您想添加一些东西,请打开一张票。

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

相关问题 在java应用程序中保存用户设置的最佳方法是什么? - What is the best way to save user settings in java application? 有没有一种方法可以将Java应用程序添加到我的github网站,以便我的个人网站具有该应用程序的实时演示? - Is there a way to add a java application to my github website so that my personal website has a live demo of the app? 与Java桌面应用程序中的数据库交互的最佳方法 - Best way to interact with database in java desktop application 为桌面应用程序定义自定义设置的最佳方法? - Best way to define custom settings for desktop-application? 在Java应用程序中保存数据的最佳方法? - Best way to save data in a Java application? 在Java桌面应用程序中进行数据库访问的最佳方法 - Best way to do database access in a Java desktop application 将Java桌面应用程序部署到多个平台的最佳方法是什么? - What is the best way to deploy a Java desktop application to multiple platforms? 移植 Java 桌面应用程序以在浏览器中运行的最佳方法是什么? - What is the best way to port a java desktop application to run in browser? 在Java桌面应用程序中保留数据的最佳方法是什么? - What's the best way to persist data in a Java Desktop Application? 如何设置要在桌面应用程序和Android App中使用的Java库 - How to set my java library to be used in desktop application and Android App
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM