`
Tristan_S
  • 浏览: 383424 次
  • 性别: Icon_minigender_1
  • 来自: 上海
社区版块
存档分类
最新评论

MessageFormat

 
阅读更多
资源文件的占位符使用
error_message=CI {0} not found {1}


public class ResourceBundleUtils {

	static ResourceBundle messages;
	
	static {
		if (messages == null) {
			Locale currentLocale;
			currentLocale = new Locale("en", "US");
			messages = ResourceBundle.getBundle("conf/ErrorMessagesBundle",
					currentLocale);
			
		}
	}

	public static void main(String[] args) {
		System.out.println(ResourceBundleUtils.getMessage("error_message"));
		String[] s = {"test"};
		System.out.println(ResourceBundleUtils.getMessage("error_message", s));
	}

	public static String getMessage(String key) {
		return messages.getString(key);
	}
	
	public static String getMessage(String key, String[] args) {
		String s =  messages.getString(key);
		return MessageFormat.format(s, args);
	}
}
分享到:
| JBPM
评论

相关推荐

Global site tag (gtag.js) - Google Analytics