使用NVelocity模板引擎 页面怎么获取想要的数据 5
后台代码:publicvoidProcessRequest(HttpContextcontext){context.Response.ContentType="text/...
后台代码:
public void ProcessRequest(HttpContext context)
{
context.Response.ContentType = "text/html";
DataTable change = SqlHelper.ExecuteDataTable("select * from T_CHANGE");
var data = new { Change = change.Rows};
string html = CommonHelper.RenderHtml("../templates/front/index.html", data);
context.Response.Write(html);
}
public bool IsReusable
{
get
{
return false;
}
前台代码:
<div class="care">
<div class="container">
<div class="care-top">
<h3>最新交易信息</h3>
<P>Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s,</P>
</div>
<div class="care-bottom">
<div class="col-md-4 c-bottom">
<div class="care-bottom-left">
<img src = "$p.Change.ChangePhoto" alt=""> //在此处显示从数据库中差找出来的记录的图片(表从的是相对路径)
<h4>variations of passages</h4>
<p> which don't look even slightly believable. If you are going to use a passage of Lorem Ipsum, you need to be sure there isn't anything embarrassing hidden in the middle of text.</p>
<div class="view">
<a href="change.html">详细信息</a>
</div>
</div>
</div> 展开
public void ProcessRequest(HttpContext context)
{
context.Response.ContentType = "text/html";
DataTable change = SqlHelper.ExecuteDataTable("select * from T_CHANGE");
var data = new { Change = change.Rows};
string html = CommonHelper.RenderHtml("../templates/front/index.html", data);
context.Response.Write(html);
}
public bool IsReusable
{
get
{
return false;
}
前台代码:
<div class="care">
<div class="container">
<div class="care-top">
<h3>最新交易信息</h3>
<P>Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s,</P>
</div>
<div class="care-bottom">
<div class="col-md-4 c-bottom">
<div class="care-bottom-left">
<img src = "$p.Change.ChangePhoto" alt=""> //在此处显示从数据库中差找出来的记录的图片(表从的是相对路径)
<h4>variations of passages</h4>
<p> which don't look even slightly believable. If you are going to use a passage of Lorem Ipsum, you need to be sure there isn't anything embarrassing hidden in the middle of text.</p>
<div class="view">
<a href="change.html">详细信息</a>
</div>
</div>
</div> 展开
1个回答
展开全部
您好:首先:在Castle Project上下载一个CastleProject包,我下载的是CastleProject-1.0-RC3.msi
安装后,在其下的bin目录中可找到NVelocity.dll(NET项目中将用到),并将其复制出来放到我的测试WEB/BIN目录下。
到castleproject上看了一下using it大致有四步: 先要引入以下名称空间: using Commons.Collections; using NVelocity; using NVelocity.App; using NVelocity.Context;
第一步:Creating a VelocityEngine也就是创建一个VelocityEngine的实例
VelocityEngine velocity = new VelocityEngine(); //也可以使用带参构造函数直接实例。 ExtendedProperties props = new ExtendedProperties(); velocity.Init(props);
第二步:Creating the Template加载模板文件
这时通过的是Template类,并使用VelocityEngine的GetTemplate方法加载模板 Template template = velocity.GetTemplate(@"path/to/myfirsttemplate.vm");
第三步:Merging the template整合模板
VelocityContext context = new VelocityContext(); context.Put("from", "somewhere"); context.Put("to", "someone");
context.Put("subject", "Welcome to NVelocity"); context.Put("customer", new Customer("John Doe") );
第四步:创建一个IO流来输出模板内容。推荐使用StringWriter(因为template中以string形式存放)
StringWriter writer = new StringWriter(); template.Merge(context, writer); Response.Write(writer.ToString());
安装后,在其下的bin目录中可找到NVelocity.dll(NET项目中将用到),并将其复制出来放到我的测试WEB/BIN目录下。
到castleproject上看了一下using it大致有四步: 先要引入以下名称空间: using Commons.Collections; using NVelocity; using NVelocity.App; using NVelocity.Context;
第一步:Creating a VelocityEngine也就是创建一个VelocityEngine的实例
VelocityEngine velocity = new VelocityEngine(); //也可以使用带参构造函数直接实例。 ExtendedProperties props = new ExtendedProperties(); velocity.Init(props);
第二步:Creating the Template加载模板文件
这时通过的是Template类,并使用VelocityEngine的GetTemplate方法加载模板 Template template = velocity.GetTemplate(@"path/to/myfirsttemplate.vm");
第三步:Merging the template整合模板
VelocityContext context = new VelocityContext(); context.Put("from", "somewhere"); context.Put("to", "someone");
context.Put("subject", "Welcome to NVelocity"); context.Put("customer", new Customer("John Doe") );
第四步:创建一个IO流来输出模板内容。推荐使用StringWriter(因为template中以string形式存放)
StringWriter writer = new StringWriter(); template.Merge(context, writer); Response.Write(writer.ToString());
追问
谢谢您的回答 首先 我已近引用了NVelocity 只是后台通过数据库查找的数据不知道前台该怎么写出来 也就是我写汉字注释的地方 该怎么写
上海华然企业咨询
2024-10-21 广告
2024-10-21 广告
上海华然企业咨询有限公司专注于AI与数据合规咨询服务。我们的核心团队来自头部互联网企业、红圈律所和专业安全服务机构。凭借深刻的AI产品理解、上百个AI产品的合规咨询和算法备案经验,为客户提供专业的算法备案、AI安全评估、数据出境等合规服务,...
点击进入详情页
本回答由上海华然企业咨询提供
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询