看了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
交口称赞 阅读(3492)
评论(8) 编辑 收藏 所属分类:
freemarker