看了2天freemarker的源碼,終于有了收獲,通過ResourceBundleModel這個對象就能在freemarker中使用資源文件了。。。。。。。。。。。。
程序中這樣寫:
ResourceBundle?RESOURCE_BUNDLE?=?ResourceBundle.getBundle("ApplicationResources");
???ResourceBundleModel?rsbm?=?new?ResourceBundleModel(RESOURCE_BUNDLE,new?BeansWrapper());
???root.put("bundle",?rsbm);
模板中這樣寫
<html>
<head>
??<title>歡迎!</title>
??<META?HTTP-EQUIV="Content-Type"?CONTENT="text/html;?charset=utf-8">
</head>
<body>
??<h1>你好?${user}!</h1>
??<h1>Welcome?${bundle("name")}</h1>
??<h1>${bundle("hello","hermit")}</h1>
</body>
</html>
中文結果
<html>
<head>
??<title>歡迎!</title>
??<META?HTTP-EQUIV="Content-Type"?CONTENT="text/html;?charset=utf-8">
</head>
<body>
??<h1>你好?hermit!</h1>
??<h1>Welcome?交口稱贊</h1>
??<h1>你好?hermit!</h1>
</body>
</html>

英文
<html>
<head>
??<title>歡迎!</title>
??<META?HTTP-EQUIV="Content-Type"?CONTENT="text/html;?charset=utf-8">
</head>
<body>
??<h1>你好?hermit!</h1>
??<h1>Welcome?hermit</h1>
??<h1>hello?hermit!</h1>
</body>
</html>
posted on 2007-05-11 10:27
交口稱贊 閱讀(3503)
評論(8) 編輯 收藏 所屬分類:
freemarker