zoukankan      html  css  js  c++  java
  • 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[]):$arr.get_item(0)

    11.分割字符串

    #set($str="111#222")
    #set($arr=$UtilHelper.SpiltString("$str","#"))
    <p>$arr.length</p>
    #foreach($item in $arr)
    <h2>$item</h2>
    #end

  • 相关阅读:
    [学习笔记]基于值域预处理的快速 GCD
    [学习笔记]整除偏序与zeta变换、Möbius变换、lcm卷积、gcd卷积
    [学习笔记]MinMax容斥
    [学习笔记]Pollard Rho算法
    [学习笔记]Miller Rabin测试
    [学习笔记]万能欧几里得
    用C#写程序安装包 Joe
    linux 命令
    几个有用的php字符串过滤,转换函数
    linux挂载 Windows分区
  • 原文地址:https://www.cnblogs.com/Robert-go-go/p/4261823.html
Copyright © 2011-2022 走看看