Velocity常⽤⽅法1.字符串替换 replace
#if($!{name} != '')
#set($tempName = $!{name})
#set($tempName = $tempName.Replace('abc','def'))
$tempName
#end
2.decimal数据类型转换成⼀定的字符串格式 tostring
需要计算的:如(number/1000).tostring("f1");
#if($strDecimal)
$strDecimal.ToString(""f0"")<br/>
#end <br/>
#if($objectDecimal)
$objectDecimal.Price.ToString(""f0"")<br/>
#end <br/>
#if($tableDecimal)
#foreach($model in $tableDecimal.Rows)
$model.Price.ToString(""f0"")<br/>
#end
#end
3.DateTime数据类型转换成⼀定的字符串格式 tostring
#if($datetime)
$datetime.ToString(""yyyy-MM-dd"")<br/>
#end <br/>
#if($date)
$date.time.ToString(""yyyy-MM-dd hh:mm:ss"")<br/>
#end <br/>
#if($table)
#foreach($model in $table.Rows)
$model.time.ToString(""yyyy年MM⽉dd⽇"")<br/>
#end
#end
4.Trim() 去除空格
#if($!{name} != '')
#set($tempName =$!{name})
#if($tempName == ' abc ')
还没有去除⾸尾空格<br/>
#end
#set($tempName =$tempName.Trim())
#if($tempName == 'abc')
去除成功
#end
$tempName
#end
5.获取对象条数
Datatable: $table.Rows.Count
数组: $tempList.Length
List: $tempList.Count字符串转数组去除空格
字符串长度: str.Length
6.
判断是否为’’
#if($!{name} != ‘’)
有值
#end
#if($!{name} == ‘’)
空值
#end
7.
null、notnull的⽤法
#if($!{name})
⾮空
#end
#if(! $!{name})
空
#end
8.
SubString()的⽤法
#set($tempName = $!{name})
#if($tempName.Length > 70)
$tempName.Substring(0,70)...
#else
$tempName
#end
9.velocityCount 序值
10.获取数组元素(不能直接arr[]):$_item(0)
11.分割字符串
#set($str="111#222")
#set($arr=$UtilHelper.SpiltString("$str","#"))
<p>$arr.length</p>
#foreach($item in $arr)
<h2>$item</h2>
#end
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论