How to load resource bundle messages from DB in Java?(如何在 Java 中从 DB 加载资源包消息?)
问题描述
我可以动态加载资源包吗?我可以动态编辑资源包吗?
Can I load a resource bundle dynamically? Can I edit a resource bundle dynamically?
如果我能拥有这样一个逻辑资源包(即位于上下文中而不是物理文件),那将是最好的.
It would be best if I can have such a logical resource bundle (i.e. located in context not as physical file).
如何从文件加载资源包资源?
推荐答案
你能覆盖 ListResourceBundle?它提供了一个扩展点,用于添加您自己的 Object[][]
资源密钥对.
Would you be able to override the ListResourceBundle? It provides an extension point for adding in your own Object[][]
of resource key pairs.
来自 javadoc:
From the javadoc:
public class MyResources extends ListResourceBundle {
protected Object[][] getContents() {
return new Object[][] = {
// LOCALIZE THIS
{"s1", "The disk "{1}" contains {0}."}, // MessageFormat pattern
{"s2", "1"}, // location of {0} in pattern
{"s3", "My Disk"}, // sample disk name
{"s4", "no files"}, // first ChoiceFormat choice
{"s5", "one file"}, // second ChoiceFormat choice
{"s6", "{0,number} files"}, // third ChoiceFormat choice
{"s7", "3 Mar 96"}, // sample date
{"s8", new Dimension(1,5)} // real object, not just string
// END OF MATERIAL TO LOCALIZE
};
}
}
此示例返回一个硬编码列表,但您可以修改它以从数据库或其他任何内容中返回您想要的任何内容.
This example returns a hard coded listing but you can modify that to return whatever you want from a database or anything else.
这篇关于如何在 Java 中从 DB 加载资源包消息?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何在 Java 中从 DB 加载资源包消息?


基础教程推荐
- 在 Libgdx 中处理屏幕的正确方法 2022-01-01
- Java:带有char数组的println给出乱码 2022-01-01
- “未找到匹配项"使用 matcher 的 group 方法时 2022-01-01
- Java Keytool 导入证书后出错,"keytool error: java.io.FileNotFoundException &拒绝访问" 2022-01-01
- FirebaseListAdapter 不推送聊天应用程序的单个项目 - Firebase-Ui 3.1 2022-01-01
- 设置 bean 时出现 Nullpointerexception 2022-01-01
- 如何使用 Java 创建 X509 证书? 2022-01-01
- 减少 JVM 暂停时间 >1 秒使用 UseConcMarkSweepGC 2022-01-01
- 降序排序:Java Map 2022-01-01
- 无法使用修饰符“public final"访问 java.util.Ha 2022-01-01