StringManager与ResourceBundle
程序员文章站
2022-03-26 17:09:38
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
上一篇: 【Java用法】Java 过滤html标签获取纯文本信息
下一篇: php如何将数组下标去掉