[导入]NVelocity 模版引擎

本文介绍了如何使用NVelocity模板引擎进行简单的样例演示,并展示了如何将数据模型与模板结合生成输出。文中还提及了编译过程中需要注意的问题及兼容性情况。

今天用了一下 NVelocity, 感觉还不错, 虽然最后的release 版 是2003年的, 但和vs 2008 以及范型等兼容性没有问题。
Write a Simple sample:

Template:

.NET
Code:
 public class Game
{ public string GameName{get;set;} public string GameType{get;set;} public int Year{get;set;}
} private void btnRender_Click(object sender,
EventArgs e) { //tbTemplate.Text; Velocity.Init("nvelocity.properties");
VelocityContext context = new VelocityContext();
Game game1 = new Game
{ GameName = "DOOM",
GameType = "FST",
Year = 1990
}; context.Put("name", "Velocity");
context.Put("project", "Jakarta");
context.Put("game1",
game1); List<String> strList = new List<String>();
strList.Add("Apple");
strList.Add("Orange");
strList.Add("Banana");
context.Put("fruits",
strList); //Template
template = new Template(); StringWriter writer = new StringWriter();
Velocity.Evaluate(context, writer, "string1",
tbTemplate.Text); tbResult.Text = writer.ToString();
}
Output:
 
若从源码编译: 几点需要注意

1) 它所用的log4net 版本比较老, 可能有兼容性问题

2) directive.properties 和 nvelocity.properties 两个文件需要设成 Embedded Resource

Links:
http://nvelocity.sourceforge.net/
http://velocity.apache.org

> aggbug.ashx?id=37770d40-9861-43f3-a6ff-f69c608908f1
文章来源: http://www.hifar.com/blog/2008/01/09/NVelocity%e6%a8%a1%e7%89%88%e5%bc%95%e6%93%8e.aspx

转载于:https://www.cnblogs.com/hifar/archive/2008/01/28/1056038.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值