8个主要的Velocity语法使用说明
8个主要的Velocity语法使用说明,分别是:Velocity表达式,Velocity注释,Velocity循环,Velocity条件判断,Velocity赋值,Velocity调试,Velocity宏,Velocity判断空。下面分别学习一下
表达式
访问JavaBeans
$someBean或${someBean}
读Properties
$bean.name或${bean.name} ## 访问bean.getName()方法或是$bean.get(“name”)方法
写Properties
#set ($bean.name = “value”)
或#set (${bean.name} = “value”) ## 访问bean.setName(“value”)方法
调用方法
$uri.setTarget(“target.vm”)
注释
行注释
## line comments
块注释
#* block
comments
*#
文档注释
#** document
comments
*#
循环
循环语句:
#foreach ($item in $collection)
($velocityCount) item is $item
#end
其中velocityCount是一特殊循环变量,用来指出循环的次数(1-based)
条件判断
条件判断
#if ($order.total == 0)
No charge
#else
$order.total
#end
赋值
赋值
#set ($customer = $order.customer)
四则运算
#set ($sum = $num1 + $num2)
#set ($sub = $num1 - $num2)
#set ($mul = $num1 * $num2)
#set ($div = $num1 / $num2)
#set ($mod = $num1 % $num2)
调试
暂停执行
#if ($debug) #stop #end
调试表达式
$user ## 显示user.toString()
$user.class ## 显示user.getClass()
$user.name ## 显示user.getName().toString()
$user.name.class ## 显示user.getName().getClass()
宏
定义宏
#macro ( errorMessage $field )
#if ( !$field.valid )
<div class="formError">* $field.message</div>
#end
#end
使用宏
<td>#errorMessage ( $group.lastName )</td>
判断空
判断:$bean不为null或Boolean.TRUE
#if ($bean) … #end
判断字符串空:””或null
#if ($stringUtil.isEmpty($str)) … #end
判断字符串非空:非””和null
#if ($stringUtil.isNotEmpty($str)) … #end
转自: http://www.ablanxue.com/prone_10843_1.html
8个主要的Velocity语法使用说明的更多相关文章
- 最新Velocity使用和Velocity语法
Velocity语法 Velocity的使用要用到下面几个包,可以从官网下载,commons-collections.jar,velocity-1.4.jar,velocity-dept.jar; 1 ...
- Velocity 语法示例
一.简介: 1)它允许任何人使用简单而强大的模板语言来引用定义在 java 代码中的对象" 2)Velocity是一个基于java的模板引擎,简称VTL(Velocity Template ...
- Velocity 语法(转)
一.基本语法 1."#"用来标识Velocity的脚本语句,包括#set.#if .#else.#end.#foreach.#end.#iinclude.#parse.#macro ...
- 【转】Velocity 语法
一.基本语法 1."#"用来标识Velocity的脚本语句,包括#set.#if .#else.#end.#foreach.#end.#iinclude.#parse.#macro ...
- Velocity语法--转载
Velocity是一个基于java的模板引擎(template engine),它允许任何人仅仅简单的使用模板语言(template language)来引用由java代码定义的对象.作为一个比较完善 ...
- Velocity 语法及其在springMVC中的配置
强烈推荐具体的整合博客:http://blog.csdn.net/duqi_2009/article/details/47752169 整合文章中有几处问题: xml中配置的vm视图解析器,应该按照本 ...
- nginx location语法使用说明
语法规则: location [=|~|~*|^~] /uri/ { … } = 开头表示精确匹配 ^~ 开头表示uri以某个常规字符串开头,理解为匹配 url路径即可.nginx不对url做编码,因 ...
- velocity语法
1.声明变量 #set($var = XXX) 右边可以是以下的内容 Variable reference String literal Property reference Method refer ...
- Velocity 语法详解
Velocity是基于Java的模板引擎,它允许页面设计者引用Java中定义的方法.页面设计者和Java开发者能够同时使用MVC的模式开发网站,这样网页设计者能够把精力放在页面的设计上,程序员也可以把 ...
随机推荐
- 第八篇:SOUI中控件事件的响应
SOUI中提供了大部分常用的win32标准控件的实现,如pushbutton, checkbox, radiobox, edit, richedit, listbox, combobox, treec ...
- xcode6 下 ios simulator 有 Home 键么?
4s之前 ,现在,只能用command+shift+h来代替
- Lingo语法
基本语法 ! 注释,末尾需要分号 ~ 分隔符 集成员无论用何种字符字符标记,它的索引都是从1开始连续计数 在数据声明中输入两个相连的逗号表示该位置对应的集成员的属性值未知. init: endinit ...
- 【POI】使用POI处理xlsx的cell中的超链接 和 插入图片 和 设置打印区域
使用POI对xlsx中插入超链接和 插入图片 package com.it.poiTest; import java.awt.image.BufferedImage; import java.io.B ...
- 软件开发中的完整测试所包括的环节UT、IT、ST、UAT
软件开发中的完成测试环境所包括的环节包括:UT.IT.ST.UAT UT = Unit Test 单元测试 IT = System Integration Test 集成测试ST = System T ...
- LoadRunner编程之跳出迭代【exit(-1)和return 0】
只运行了一次迭代,就结束了. LR脚本实践:关于lr中exit(-1)和return 0的区别 exit(-1):从当前action里面exit(-1)所在行,当前迭代里面直接退出来,终止运行: ...
- 基线 css
原文地址:http://blog.jobbole.com/31926/ 英文原文:CSS Baseline,编译:飞鸟分享 译者注:网页设计布局中一直比较流行网格对齐,但只是针对水平的对齐,很少或者没 ...
- redis 的使用 (基础, key操作, string类型操作)
使用redis set 类型: 没有重复元素 list 链表类型 有重复累型 sort set 类型 没有重复元素 1.1 存储数据 读取数据 // 数据储存在 内存中 set name laowen ...
- redis 的安装
1: redis 是什么 Redis is an open source (BSD licensed), in-memory data structure store, used as databas ...
- Fzu2109 Mountain Number 数位dp
Accept: 189 Submit: 461Time Limit: 1000 mSec Memory Limit : 32768 KB Problem Description One ...