- 浏览: 70977 次
- 性别:
- 来自: 北京
文章分类
最新评论
-
george.gu:
lqjacklee 写道怎么解决。。 First: Conf ...
Bad version number in .class file -
lqjacklee:
怎么解决。。
Bad version number in .class file -
flyqantas:
would you pleade left more mate ...
UML Extension
You can find velocity mannual from http://velocity.apache.org/engine/devel/user-guide.html.
Here is summarize on how to use velocity.
Velocity Usage:
Velocity is a Java-based template engine.
We can use velocity to define web page instead of JSP, there are several advantages:
- It permits web page designers to reference methods defined in Java code. Web designers can work in parallel with Java programmers to develop web sites according to the Model-View-Controller (MVC) model, meaning that web page designers can focus solely on creating a well-designed site, and programmers can focus solely on writing top-notch code.
- Simplify web page logical and make it more easy to be managed by web-designer
- Web page written in velocity template can be updated without re-deploy you web application.
We can also use velocity to generate other output based on template:
- XML
- SQL
- Some other file template with dynamic data by defining them in velocity syntax.
Variable Definition:
The shorthand notation of a variable consists of a leading "$" character followed by a VTL Identifier. A VTL Identifier must start with an alphabetic character (a .. z or A .. Z). The rest of the characters are limited to the following types of characters:
- alphabetic (a .. z, A .. Z)
- numeric (0 .. 9)
- hyphen ("-")
- underscore ("_")
Following definition have different meaning:
$count:
Usage: #set($count=10)
define a variable named "count"
$count-1:
Usage: #set($count-1=10)
define a variable named "count-1". Warning: it is not a evaluation to get the value of $count minus 1.
$count -1:
Usage: #set($count=$count -1)
Error!
Exception : org.apache.velocity.exception.ParseErrorException: Encountered "-1" at...
$count - 1:
Usage: #set($count=$count - 1)
execute an evaluation which get result of $count minus 1.
has same value as "$count + -1"
${count}-1:
Usage: #set($count=${count}-1)
Error!
Get the same error as "$count -1".
${count}- 1:
Usage: #set($count=${count}- 1)
execute an evaluation which get result of $count minus 1.
has same value as "${count}+ -1"
Exception
But if you want to display "10-1" in your output, you can use following template:
#set( $count=10)
${count}-1
#[[
$count-1 will lead to "$count-1", because there is no variable named "count-1";
$count -1 will lead to "10 -1" which has one more space than "10-1".
$!count-1 will lead to " ", because there is no variable named "count-1";
]]#
Quiet Reference Notation "!" and conditional logical NOT "!"
When Velocity encounters an undefined reference, its normal behavior is to output the image of the reference. For example, suppose the following reference appears as part of a VTL template.
my email is "$email"
In case there is no variable defined for $email, it will display: my email is "$email".
If you set Quiet Reference Notation as following:
my email is "$!email"
In case there is no variable defined for $email, it will display: my email is "".
But conditional logical NOT is different:
#if(!$email)
I have no email.
#else
my email is "#email"
#end
Note: if only one variable is evaluated to determine whether it is true, like if($email). Which will happen under one of two circumstances:
- $email is a boolean (true/false) which has a true value, or
- $email is NOT a boolean and its value is not null.
#include() vs. #parse():
- include() can contain a set of files separated by commas, like: include("file1.vm", "file2.vm", ...) But parse() can only contain one file.
- Velocity does not render variables inside included files, but the variables inside parse file will be rendered.
- You can use variable to replace filename in both.
Properties reference to Variable
public class JavaBean {
private String a;
private String b = "Iamb";
public JavaBean() {
}
public String geta() {
return "Iama";
}
public String getA() {
return "IamA";
}
}
|
$bean.a
$bean.A
$bean.b
|
VelocityContext context = new VelocityContext();
context.put("bean", new JavaBean());
PrintWriter writer = new PrintWriter(System.out);
Template template = Velocity.getTemplate("test.vm");
template.merge(context, writer);
|
- geta()
- getA()
- get("a")
- isA()
Directive:
#set:
literal:
Condition:
Loops:
velocity.properties:
发表评论
-
javax.naming.CommunicationException: remote side declared peer gone on this JVM.
2012-07-11 09:44 2329javax.naming.ServiceUnavailable ... -
Generate special format numbers
2012-04-27 00:06 867DecimalFormat df = new DecimalF ... -
Singleton Service in Weblogic Cluster
2012-03-21 00:12 653http://blog.csdn.net/mobicents/ ... -
Scheduled ThreadPool Executor suppressed or stopped after error happen
2012-03-20 16:54 1004ScheduledThreadPoolExecutor ... -
Bad version number in .class file
2012-01-27 00:35 845Bad version number in .class fi ... -
User Data Header in SMPP SUBMIT_SM
2012-01-25 22:30 2298SMPP optional Parameters for ... -
jQuery study
2011-12-28 00:44 0to be study -
Java is Pass-by-Value or Pass-by-Reference?
2011-12-19 19:18 653What's saved in Object Referenc ... -
java.util.Properties: a subclass of java.util.Hashtable
2011-12-13 06:57 735I met a problem this afternoon ... -
Jmock usage
2011-12-02 05:37 0Discuss how Jmock working. -
Oracle Index Usage
2011-12-15 05:26 570Like a hash mapping for record' ... -
AOP(2):AOP与动态代理JDK Proxy and Cglib Proxy
2011-05-12 16:20 967使用动态代理(JDK Proxy 或者Cglib Proxy) ... -
AOP(1):应用中的几个小故事
2011-05-09 21:49 937I had heared about AOP almost 7 ... -
异步系统设计:push vs pull
2011-05-02 23:59 1109今天讨论问题时,有个同事说系统A是主动去系统B里“拿”消息,我 ... -
Java Regular Expression (Java正则表达式)
2011-04-23 06:58 892In current Project, we need to ... -
XML Parser:DOM + XPath
2011-04-23 06:30 1159There are many kinds of XML Par ... -
File upload and download in Java Web Application.
2011-04-21 21:08 1671最近在项目中遇到一个下载文件的老问题。之所以说是老问题,因为在 ... -
Manage zip content using Java APIs
2011-04-21 18:14 985JDK provide a set of utils to c ... -
Beanshell: how and where to use beanshell
2011-04-21 00:33 2050How to use beanshell beansh ... -
OXM: JAXB2.0 in JDK1.6
2011-04-20 22:53 12041.1.1 JAXB 2.0: ObjectàXML ...
相关推荐
Usage var mat = require('mat') var velocity = require('mat-velocity') var rewrite = require('mat-rewrite') mat.task('daily', function () { mat.url([/\.vm/]) .use(velocity({ })) }) api 用来处理vm的...
##Usage 在你的框架 package.js 中引用这个包,然后在服务器上使用类似的东西: Meteor . call ( 'velocity/mirrors/request' , { framework : 'myFramework' } ) ; VelocityMirrors . find ( { framework : '...
amazing: Velocity 前端工程问题集成解决方案 Usage 全局安装amazing npm install -g amazing 到web工程的根目录下 cd /(webapp) 初始化本地服务器web工程加载目录 amazing -i 启动服务器 amazing Others 自定义端口...
A smart and simple plugin that provides keyboard shortcut access for Dash, Velocity or Zeal in IntelliJ IDEA, RubyMine, WebStorm, PhpStorm, PyCharm, DataGrip, CLion, GoLand and Android Studio. ...
Since the writing of the first edition of this book, usage of the Global Positioning System (GPS) has become nearly ubiquitous. GPS provides the position, velocity, and timing information that enables...
While this documentation will cover the features and usage of the SDK, because of the academically challenging nature of the subject matter, it is assumed that you have mastered the material covered ...
您的支持帮助我们继续我们在 Velocity 和相关框架方面的工作。 #安装 meteor add xolvio:patcher#Usage 这个包设置了debugOnly标志,这意味着它不会被捆绑到应用程序中。 这也意味着您只能将其作为弱依赖引用,...
Electronics for Imaging303 Velocity Way Foster City, California 94404 USAEmail: Michael.Baer@efi.comAbstract— Let P = {p(i)} be a measure of strictly positive probabilities on the set of nonnegative ...
* Servlet adapter provided to let you deploy any Restlet application in Servlet compliant containers like Tomcat, when the usage of standalone HTTP connectors is not possible. * Implementation of ...
(e) usage period: 10 years, minor overhaul period: 1 year, and overhaul period: 3 years; (f) power source is alternating three-phase voltage; (g) small-batch production in medium scale machinery ...
14.4. Velocity和FreeMarker 14.4.1. 需要的资源 14.4.2. Context 配置 14.4.3. 创建模板 14.4.4. 高级配置 14.4.5. 绑定支持和表单处理 14.5. XSLT 14.5.1. 写在段首 14.5.2. 小结 14.6. 文档视图(PDF/...
14.4. Velocity和FreeMarker 14.4.1. 需要的资源 14.4.2. Context 配置 14.4.3. 创建模板 14.4.4. 高级配置 14.4.5. 绑定支持和表单处理 14.5. XSLT 14.5.1. 写在段首 14.5.2. 小结 14.6. 文档视图(PDF/...
14.4. Velocity和FreeMarker 14.4.1. 需要的资源 14.4.2. Context 配置 14.4.3. 创建模板 14.4.4. 高级配置 14.4.5. 绑定支持和表单处理 14.5. XSLT 14.5.1. 写在段首 14.5.2. 小结 14.6. 文档视图(PDF/...