标签:
NVelocity.dll是Java中常用的一个模版,下面是常用的模版引擎
1,返回string类型的html代码
1 public string rtnStr(string username, string password) 2 { 3 string rtn = string.Empty; 4 VelocityEngine vltEngine = new VelocityEngine(); 5 vltEngine.SetProperty(RuntimeConstants.RESOURCE_LOADER, "file"); 6 vltEngine.SetProperty(RuntimeConstants.FILE_RESOURCE_LOADER_PATH, System.Web.Hosting.HostingEnvironment.MapPath("~/Templates"));//模板文件所在的文件夹 7 vltEngine.Init(); 8 9 VelocityContext vltContext = new VelocityContext(); 10 vltContext.Put("username", username);//设置参数,在模板中可以通过$data来引用 11 vltContext.Put("pwd", password); 12 Template vltTemplate = vltEngine.GetTemplate("Login.htm"); 13 System.IO.StringWriter vltWriter = new System.IO.StringWriter(); 14 vltTemplate.Merge(vltContext, vltWriter); 15 16 rtn = vltWriter.GetStringBuilder().ToString(); 17 return rtn; 18 }
标签:
原文地址:http://www.cnblogs.com/ningheshutong/p/4398114.html