/// <summary> /// 根据模板解析内容. /// </summary> public static string GenByTemplate(string templatePath, string templateFile, Hashtable ht, string charset) { ExtendedProperties props = new ExtendedProperties(); //使用设置初始化VelocityEngine props.AddProperty(RuntimeConstants.RESOURCE_LOADER, "file"); props.AddProperty(RuntimeConstants.FILE_RESOURCE_LOADER_PATH, templatePath); Velocity.Init(props); IContext context = new VelocityContext(); if (ht != null && ht.Count > 0) { IDictionaryEnumerator dictenum = ht.GetEnumerator(); while (dictenum.MoveNext()) { String key = dictenum.Key.ToString(); context.Put(key, dictenum.Value); } } Template template = Velocity.GetTemplate(templateFile, charset); StringWriter writer = new StringWriter(); template.Merge(context, writer); Velocity.ClearProperty(RuntimeConstants.FILE_RESOURCE_LOADER_PATH); // 清除掉该地址 return(writer.ToString()); }