Velocity判断空值方法:
依据:
$username与$!username的区别,当找不到username的时候,$username返回字符串"$username",而$!username返回空字符串""
所以:#set($!username=='') 可以判断字符串是否为空
以下为Velocity脚本摘要
1、声明:#set ($var=XXX)
左边可以是以下的内容
Variable reference
String literal
Property reference
Method reference
Number literal #set ($i=1)
ArrayList #set ($arr=["yt1","t2"])
技持算术运算符
2、注释:
单行## XXX
多行#* xxx
xxxx
xxxxxxxxxxxx*#
References 引用的类型
3、变量 Variables
以 "$" 开头,第一个字符必须为字母。character followed by a VTL Identifier. (a .. z
or A .. Z).
变量可以包含的字符有以下内容:
alphabetic (a .. z, A .. Z)
numeric (0 .. 9)
hyphen ("-")
underscore ("_")
4、Properties
$Identifier.Identifier
$user.name
hashtable user中的的name值.类似:user.get("name")
5、Methods
object user.getName() = $user.getName()
6、Formal Reference Notation
用{}把变量名跟字符串分开
如
#set ($user="csy"}
${user}name
返回csyname
$username
$!username
$与$!的区别
当找不到username的时候,$username返回字符串"$username",而$!username返回空字符串""
7、双引号 与 引号
#set ($var="helo")
test"$var" 返回testhello
test'$var' 返回test'$var'
可以通过设置 stringliterals.interpolate=false改变默认处理方式
8、条件语句
#if( $foo )
<strong>Velocity!</strong>
#end
#if($foo)
#elseif()
#else
#end
当$foo为null或为Boolean对象的false值执行.
9、逻辑运算符:== && || !
10、循环语句#foreach($var in $arrays ) // 集合包含下面三种Vector, a Hashtable or an Array
#end
#foreach( $product in $allProducts )
<li>$product</li>
#end
#foreach( $key in $allProducts.keySet() )
<li>Key: $key -> Value: $allProducts.get($key)</li>
#end
#foreach( $customer in $customerList )
<tr><td>$velocityCount</td><td>$customer.Name</td></tr>
#end
11、velocityCount变量在配置文件中定义
# Default name of the loop counter
# variable reference.
directive.foreach.counter.name = velocityCount
# Default starting value of the loop
# counter variable reference.
directive.foreach.counter.initial.value = 1
12、包含文件
#include( "one.gif","two.txt","three.htm" )
13、Parse导入脚本
#parse("me.vm" )
14、#stop 停止执行并返回
15、定义宏Velocimacros ,相当于函数 支持包含功能
#macro( d )
<tr><td></td></tr>
#end
调用
#d()
16、带参数的宏
#macro( tablerows $color $somelist )
#foreach( $something in $somelist )
<tr><td bgcolor=$color>$something</td></tr>
#end
#end
17、Range Operator
#foreach( $foo in [1..5] )
分享到:
相关推荐
Velocity脚本简明教程
EasyJWeb-Velocity脚本简明教程
Velocity的脚本语言
很多朋友不清楚在mybatis可以使用各种脚本语言来定义Mapper文件里面的动态SQL;目前mybatis支持的脚本语言有XML(默认的);Velocity和Freemarker三种...下面通过本文给大家介绍Mybatis velocity脚本的使用,一起看看吧
Velocity脚本语法摘要
NULL 博文链接:https://xml.iteye.com/blog/1964213
Velocity是一个基于java的模板引擎(template engine)。它允许任何人仅仅简单的使用模板语言(template language)来引用由java代码定义的对象。
Velocity模板引擎Velocity模板引擎Velocity模板引擎Velocity模板引擎Velocity模板引擎Velocity模板引擎Velocity模板引擎Velocity模板引擎Velocity模板引擎Velocity模板引擎
非常有用的脚本,拷贝到项目中即可使用。 在任意GameObject下的脚本中直接使用: public VelocityEstimator velocityEstimator;...无需添加刚体即可获得对象Velocity,对于砍切动作等都是很方便的脚本。
Velocity Velocity Velocity Velocity Velocity Velocity Velocity Velocity Velocity Velocity
Velocity 和 FreeMarker区别 对于大部分的应用来说,使用 FreeMarker 比 Velocity 更简单,因为 Velocity 还必须编写一些自定义的
Velocity用户指南旨在帮助页面设计者和内容提供者了解Velocity和其简单而又强大的脚本语言(Velocity Template Language (VTL))。本指南中有很多示例展示了用Velocity来讲动态内容嵌入到网站之中,但是所有的VTL ...
Velocity_v2 指标
本课程从velocity engine也就是velocity引擎开始, 先讲解velocity的基本使用以及基础语法 , 然后再讲解velocity 的进阶内容velocity Tools , 以及velocity作为web项目的视图改如何使用 , 每一部分都会有一个综合案例...
赠送jar包:velocity-engine-core-2.3.jar; 赠送原API文档:velocity-engine-core-2.3-javadoc.jar; 赠送源代码:velocity-engine-core-2.3-sources.jar; 赠送Maven依赖信息文件:velocity-engine-core-2.3.pom;...
打开网址:http://www.web-tag.net/all_17.htm 就是velocity标签大全 、教程 或下载CHM格式帮助文档
在使用velocity作为视图层时候,经常会碰到为空的判断,这里整理了velocity为空判断
Velocity教程
Velocity入门教程,语法,Velocity布局,Spring框架集成Velocity
赠送jar包:velocity-engine-core-2.3.jar 赠送原API文档:velocity-engine-core-2.3-javadoc.jar 赠送源代码:velocity-engine-core-2.3-sources.jar 包含翻译后的API文档:velocity-engine-core-2.3-javadoc-...