C#中Nvelocity的简单使用
把Nvelocity封装好的dll文件添加引用到你的项目中。
然后导入命名空间
using NVelocity;
using NVelocity.App;
using NVelocity.Runtime;
下面来写一个简单的例子
/*
*加载引擎
*/
VelocityEngine vlte = new VelocityEngine();
vlte.SetProperty(RuntimeConstants.RESOURCE_LOADER, "file");
vlte.SetProperty(RuntimeConstants.FILE_RESOURCE_LOADER_PATH,Server.MapPath("~/"));
vlte.Init();
/*
*填充内容
*/
VelocityContext vlc = new VelocityContext();
vlc.Put("Name", "李雷");
vlc.Put("Age","24");
/*
*指定引擎加载的模版
*/
Template vtp = vlte.GetTemplate("Model.htm");
StringWriter str =new StringWriter();
vtp.Merge(vlc, str);
Response.Write(str.GetStringBuilder().ToString());
浙公网安备 33010602011771号