日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 人文社科 > 生活经验 >内容正文

生活经验

VTL-vm模板的变量用法

發(fā)布時間:2023/11/27 生活经验 46 豆豆
生活随笔 收集整理的這篇文章主要介紹了 VTL-vm模板的变量用法 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

加載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'),四舍五入,保留兩小數(shù)。toString();可以加很多的參數(shù),查查參數(shù)表.
#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()的循環(huán)用法。
<select id="sels">
?#foreach($time in [1..$checkorder.TimeCount])
??<option value=$time>$time</option>
?#end
</select>
---------------------------------------------------------------------------------------
2008-1-5:作VTL表達式,Castle工程
VTL表達式不區(qū)分大小寫,可以調(diào)用方法,屬性,
//$velocityCount是統(tǒng)計循環(huán)的次數(shù),從1弄開始計算
#set($foo="Holle") ${foo}world
##:是單行注釋。#**#:多行注釋。
<table>
#foreach($info in $array)
?<tr>
?<td>$velocityCount ##統(tǒng)計循環(huán)的次數(shù)從1開始計</td>
?<td>$!{info.name}</td>
?<td>$!{info.Password}</td>
?<td>$!{info.Age}</td>
?<td>$!{info.getvalue}</td>
?</tr>
#end
</table>
循環(huán)Hashtable是的用法
$allProducts是Hashtable的對象
#foreach($var in $allProducts)
?##var.key:獲取鍵 var.value:獲取值
?$!{var.key}->$!{var.value}
#end
//另一種Hashtable的循環(huán)用法
vm頁面用關(guān)鍵字點鍵名。
<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
//當有數(shù)組是判斷是否是數(shù)
#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
-----------------------------------------------------------------------------------------------------
用<!--? -->:來注釋頁面上用的,不能有套用會無法注釋的如:<!-- <!-- --> -->
---------------------------------------------------------------------------------------------------------
//會依次顯示,當翻頁面時也會接著上一頁繼續(xù)顯示編號。其中14為每一頁顯示的條數(shù),根據(jù)需要而調(diào)整
#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的頁面數(shù)據(jù)加載。
---------------------*.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數(shù)據(jù)綁定頁面------------------------------------
#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類型數(shù)據(jù)的方法。
#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數(shù)據(jù)綁定頁面-----------------------------------------------------
#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);
}

轉(zhuǎn)載于:https://www.cnblogs.com/wei9931/archive/2009/05/23/1487931.html

總結(jié)

以上是生活随笔為你收集整理的VTL-vm模板的变量用法的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。