`

VTL-vm模板的变量用法

 
阅读更多

VTL-vm模板的变量用法

加载foot模块页
#parse("foot.vm")

#foreach($item in $tables)
 #set($strEnd = $item.Length - 1)
 #set($sheetName = $item.Substring(0, $strEnd))
 <option value="$item">$sheetName</option>
#end

$strEnd也可以看做一个字符串来操作
$item.Substring(0,15) 取出从0开始的15个字符
------------------------------------------------------------------------------------------
//$listType才能用ToString()时,不能用$!{listType}不会出错不能被ToString();
//$listType.toString('f2'),四舍五入,保留两小数。toString();可以加很多的参数,查查参数表.
#if($listType.ToString() == "List")
 #foreach($item in $items)
 <li><a href="FindByPosition.page?positionId=$!{item.Id}">$!{item.PositionName}</a></li>
 #end
#elseif($listType.ToString() == "Select")
 <select id="position" name="employee.Position">
 <option value="-1">请选择</option>
 #foreach($item in $items)
 <option value="$!{item.Id}">$!{item.PositionName}</li>
 #end
 </select>
#end

//#foreach()的循环用法。
<select id="sels">
 #foreach($time in [1..$checkorder.TimeCount])
  <option value=$time>$time</option>
 #end
</select>
---------------------------------------------------------------------------------------
2008-1-5:作VTL表达式,Castle工程
VTL表达式不区分大小写,可以调用方法,属性,
//$velocityCount是统计循环的次数,从1弄开始计算
#set($foo="Holle") ${foo}world
##:是单行注释。#**#:多行注释。
<table>
#foreach($info in $array)
 <tr>
 <td>$velocityCount ##统计循环的次数从1开始计</td>
 <td>$!{info.name}</td>
 <td>$!{info.Password}</td>
 <td>$!{info.Age}</td>
 <td>$!{info.getvalue}</td>
 </tr>
#end
</table>
循环Hashtable是的用法
$allProducts是Hashtable的对象
#foreach($var in $allProducts)
 ##var.key:获取键 var.value:获取值
 $!{var.key}->$!{var.value}
#end
//另一种Hashtable的循环用法
vm页面用关键字点键名。
<h3>$!{hash.aa}</h3>
<h3>$!{hash.bb}</h3>
<h3>$!{hash.cc}</h3>
<h3>$!{hash.dd}</h3>
Controll层里
public void Index()
{
 Hashtable hash = new Hashtable();
 hash.Add("aa","one");
 hash.Add("bb",DateTime.MaxValue);
 hash.Add("cc",DateTime.MinValue);
 hash.Add("dd",DateTime.Now.ToString());
}
-------------------------------------------------------------------------------------
##是可以用来输出字面的意思是原样输出(注释用的)
#literal()
#foreach($woogie in $boogie)
 nothing will happen to $woogie
#end
#end
-----------------------------------------------------------------------------------------
//$type里面的一些方法,比较有用。
#if($type.ToLower() != "noservice")  ToLower():是小写字符串的方法。
ToString():
#set($index=$item.Content.IndexOf(","))
$!{item.ReceiveTime.ToString("yyyy-mm-dd HH:mm")}
$!{consumeLog.OperateDate.ToString("yyyy-MM-dd HH:mm")}
$!{consume.ConsumeDate.ToString("d")}
$!{consume.ConsumeDate.ToString("t")}
$!{sign.FirstStartTime.ToShortDateString()}与$!{sign.FirstStartTime.ToString("yyyy-MM-dd")}效果一样的。
#set($index = $customer.IndexOf(","))取得逗号位置
$r.Phone.Substring(0,7)****:取出电话号码为:1371093****
-----------------------------------------------------------------------------------------
this.ProprtBag.Add("time",DateTime.Now);
//用来判断是否为空
#if($time!="")
 <h1>$!time</h1>
#end
//当有数组是判断是否是数
#if($items.Count>0)
 #foreach($item in $items)
  $!{item}
 #end
#end
-----------------------------------------------------------------------------------------
#elseif:多重条件判断
#if(!$order)
 100001
#elseif($order.CustomerId && $order.CustomerId != "" && $order.CustomerId != $userName)
 100002
#elseif($order && ($order.CustomerId == "" || !$order.CustomerId || $order.CustomerId == $userName))
 100003
#end
-----------------------------------------------------------------------------------------------------
用<!--  -->:来注释页面上用的,不能有套用会无法注释的如:<!-- <!-- --> -->
---------------------------------------------------------------------------------------------------------
//会依次显示,当翻页面时也会接着上一页继续显示编号。其中14为每一页显示的条数,根据需要而调整
#if(!$page || $page <= 0)
 #set($page = 1)
#end
#set($rowIndex = ($page - 1) * 14 )
#foreach($log in $logDt.Rows)
 $rowIndex
#end
---------------------------------------------------------------------------------------------------------
$!{consumeLog.OperateDate.ToString("yyyy-MM-dd HH:mm")}
---------------------------------------------------------------------------------------------------------
#if(!$log.UserName || $log.UserName == "")
 <a title="邀请会员激活空间" href="javascript:sendMessage('$!{log.CardId}')"><img alt="未绑定" src="../images/noTies.gif" /></a>
 <div id="ajaxmsg"></div>
#else
 <a href="http://$!%7blog.username%7d.i.myking.cn/" target="_blank"><img alt="进入TA的个人王国" src="../images/Ties.gif" /></a>
#end
用来判断为空值时的处理
-----------------------------------------------------------------------------------------------------------
DataTable或者DataSet的页面数据加载。
---------------------*.vm----------------------------------------------------------------------------------
页面上写的是
#foreach($log in $table.Rows)
 $!{log.Id}>>>$!{log.User}>>>$!{log.Phone}
#end
----------------controller----------------------------------
public void Index()
{
 DataTable table = new DataTable();
 table.Columns.Add("Id",typeof(int));
 table.Columns.Add("User",typeof(string));
 table.Columns.Add("Phone",typeof(string));
 for(int i=0;i<3;i++)
 {
  DataRow row = table.NewRow();
  row["Id"]=i;
  row["User"]="cheng";
  row["Phone"]="2222222";
  table.Rows.Add(row);
 }
 this.ProperBag.Add("table",table);
}
----------------------------DateSet数据绑定页面------------------------------------
#foreach($t in $ds.Tables)
 <table class="month">
 <tr>
  #foreach($col in $t.Columns)
   <th>$col.ColumnName.Replace("日","")</th>
  #end
 <tr>
 #foreach($r in $t.Rows)
 <tr>
  #foreach($c in $r.ItemArray)
   <td align="center">
   #if($c==0)--#end
  #if($c>0) $c.ToString() #end</td>
 #end
 </tr>
 #end
 </table>
#end
---------------------后台的代码----------------------------------------------------
using(DataSet ds=_cardsSituation.ByCardType(CurrentMerchant.UserName,year,month))
{
 PropertyBag.Add("ds",ds);
}
-------------------------------------------------------------------------------------
//时间日期的判断
#if($!{Member.Isusedate.ToShortDateString()} =="0001-1-1")
 ----
#else
 $!{Member.Isusedate.ToShortDateString()}
#end
-------------------------------------------------------------------------------------
//用于计算剩余的值
#set($Balance = $!item.Money - $!item.FactMoney)
<td  class="last">$Balance.toString('f2')</td>
-------------------------------------------------------------------------------------
//用来显示DataTable dt类型数据的方法。
#foreach($col in $dt.Columns)
 <th>$col.ColumnName</th>
#end
<tr>
#foreach($dr in $dt.Rows)
 <tr>
 #foreach($c in $dr.ItemArray)
  <td align="center">
  #if(!$c || $c.ToString()=="" || $c.ToString()=="0")
  --
  #else
  $c.ToString()
  #end</td>
 #end
 </tr>
#end

--------------------------------------------------------------------------------------

---------------------*.vm------------------------------------
页面上写的是
#foreach($log in $table.Rows)
 $!{log.Id}>>>$!{log.User}>>>$!{log.Phone}
#end
----------------controller----------------------------------
public void Index()
{
 DataTable table = new DataTable();
 table.Columns.Add("Id",typeof(int));
 table.Columns.Add("User",typeof(string));
 table.Columns.Add("Phone",typeof(string));
 for(int i=0;i<3;i++)
 {
  DataRow row = table.NewRow();
  row["Id"]=i;
  row["User"]="cheng";
  row["Phone"]="2222222";
  table.Rows.Add(row);
 }
 this.ProperBag.Add("table",table);
}


----------------------------DateSet数据绑定页面-----------------------------------------------------
#foreach($t in $ds.Tables)
 

 <table class="month">
  <tr>
  #foreach($col in $t.Columns)
   <th>$col.ColumnName.Replace("日","")</th>
  #end
  <tr>
  #foreach($r in $t.Rows)
   <tr>
   #foreach($c in $r.ItemArray)
    <td align="center">
    #if($c==0)--#end
    #if($c>0) $c.ToString() #end</td>
   #end
   </tr>
  #end
  </table>
 #end
---------------------后台的代码
using(DataSet ds=_cardsSituation.ByCardType(CurrentMerchant.UserName,year,month))
{
 PropertyBag.Add("ds",ds);

分享到:
评论

相关推荐

    飞康VTL存储管理器(VTL-S)解决方案

    飞康VTL存储管理器(VTL-S)是整合业界领先的VTL虚拟磁带库和重复数据删除技术的革命性数据保护解决方案,可以在不改变现有备份环境及管理策略的前提下,大幅提升备份恢复的速度及可靠性。备份后自动删除重复数据,...

    飞康VTL虚拟磁带库解决方案

    飞康VTL存储管理器(VTL-S)是整合业界领先的VTL虚拟磁带库和重复数据删除技术的革命性数据保护解决方案,可以在不改变现有备份环境及管理策略的前提下,大幅提升备份恢复的速度及可靠性。备份后自动删除重复数据,...

    VTL-Tools:用于验证和转换语言JavaScript工具

    VTL工具 JavaScript工具 该文档可在文件夹中找到并。 也可在线获得。 配套 VTL Tools是monorepo。 您可以在下面找到4个软件包的4个软件包中。 @ inseefr / vtl-tools 该库尚未维护。 最新版本是0.1.15。 Editor...

    java-vtl-tools:各种VTL工具

    java-vtl-tools Java VTL工具的集合。构建并作为Docker映像运行运行“ mvn clean install”以构建应用程序本身。 构建Docker映像:docker build -t java-vtl-tools:latest 运行应用程序:docker run java-vtl-tools...

    VTL-JS

    VTL-JS

    action-vtl-test:测试动作的游乐场-vtl GitHub动作

    动作测试测试动作的游乐场-vtl GitHub动作

    VTL-Schedule-Bot:gramTelegram Vinnytsia Technical Lyceum的进度机器人计划

    欢迎使用此存储库! 这是机器人,用于在显示时间表。 到机器人 目录 动机 当我开始在学习时,一切都开始了。 当然,在第一年,很难理解在大学学习的方式。 在电报中,有一个显示了时间表。 然后我想到了为我的学校...

    华为HCIE-Storage企业专项培训视频汇总集【共5章42集】.rar

    目录:网盘文件,永久连接 统一融合存储存储 01-传统RAID 02-RAID2.0 03-Smart特性 04-Hyper特性 05-实验部分 06-nas特性 07-调优 09-故障处理 ...统一存储硬件介绍 ...VTL实验 01-VTL ...模拟器使用方法

    Apache Velocity - VTL Reference

    Apache Velocity - VTL Reference just for convenience, it's from official site documentation

    QC-VTL虚拟磁带库的产品优势

    Qbisys虚拟磁带库是Qbisys数据保护解决方案中高速存储的一个重要组建,解决了磁带和硬盘之间的性能鸿沟,...同时,QC-VTL作为Qbisys数据保护解决方案一个重要部分,在保证性能的同时,提供的是更突出的可靠性和稳定性。

    VTL-Community

    VTL社区 迈向 VTL 开发者社区 想象 一些组织正在开发与 VTL 相关的工具。 协调这些发展将为 VTL 用户带来更多清晰度并避免重复工作。 为了建立这样的合作,建议建立一个基于开源原则和方法的社区。 会员 该社区的第...

    QC-VTL虚拟磁带库

    Qbisys的QC-VTL虚拟磁带库设备,核心是一个可以模拟成磁带库的软件。QC-VTL具有卓越的性能,可以灵活适应多样的环境,从最简单的单用户、单服务器、完全没有物理磁带的环境,到复杂的网络环境:多系统,多主机和多...

    vtl reflection-开源

    C ++语言的反射API。 主要特征如下:-无需额外的翻译课程来增加内省; -基于标准预处理器指令和健壮的模板机制; -反射类,方法和属性。

    VTL500演讲PPT-PowerPointTemp.pptx

    VTL500演讲PPT-PowerPointTemp.pptx

    VTL介绍和使用

    VTL介绍和使用欢迎下载使用。VTL介绍和使用VTL介绍和使用VTL介绍和使用VTL介绍和使用

    开源VTL MHVTL配置

    开源VTL MHVTL配置 网上找到的。

    《VTL语法参考指南》中文版.pdf

    《VTL语法参考指南》中文版.pdf 模板开发语言

    个人配置VTL核心命令

    个人配置VTL核心命令

    飞康VTL2006 介绍

    飞康的vtl介绍,说的比较详细。 做存储的同学可以参考。

Global site tag (gtag.js) - Google Analytics