如何从数据库加载资源包的消息在Java中?
-
19-09-2019 - |
题
解决方案
您是否能够覆盖 ListResourceBundle的?它提供了一个扩展点,在你自己的资源键对Object[][]
加入。
根据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
};
}
}
此示例返回一个硬编码的房源,但你可以修改返回任何你想要从数据库或其他任何东西。
不隶属于 StackOverflow