StringManager与ResourceBundle
程序员文章站
2022-07-10 19:40:40
StringManager与ResourceBundleStringManager与ResourceBundle1. StringManager2. ResourceBundle类2.1 作用StringManager与ResourceBundle1. StringManager位于org.apache.catalina.util下,使用单例模式只含有一个对象,内部含有Hashtable的managers,用于存储(key,value),key为包名private StringManager(St...
StringManager与ResourceBundle
StringManager与ResourceBundle
1. StringManager
位于org.apache.catalina.util下,使用单例模式只含有一个对象,内部含有Hashtable的managers,用于存储(key,value),key为包名
private StringManager(String packageName) {
String bundleName = packageName + ".LocalStrings";
bundle = ResourceBundle.getBundle(bundleName);
}
public synchronized static StringManager getManager(String packageName) {
StringManager mgr = (StringManager)managers.get(packageName);
if (mgr == null) {
mgr = new StringManager(packageName);
managers.put(packageName, mgr);
}
return mgr;
}
2. ResourceBundle类
2.1 作用
用于实现国际化,
import javax.annotation.Resource;
import java.util.Locale;
import java.util.ResourceBundle;
/**
* @author OovEver
* 2018/1/14 22:12
*/
public class Main {
public static void main(String args[]) {
ResourceBundle bundle = ResourceBundle.getBundle("my", new Locale("zh", "CN"));
bundle.getString(key)
}
}
// getBundle内部实现
@CallerSensitive
public static final ResourceBundle getBundle(String baseName)
{
return getBundleImpl(baseName, Locale.getDefault(),
getLoader(Reflection.getCallerClass()),
getDefaultControl(baseName));
}
本文地址:https://blog.csdn.net/qq_25848311/article/details/109643795
下一篇: cdr怎么设计一个自行车停放的广告牌?