- 浏览: 73505 次
- 性别:
- 来自: 北京
文章分类
最新评论
-
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 2378javax.naming.ServiceUnavailable ... -
Generate special format numbers
2012-04-27 00:06 937DecimalFormat df = new DecimalF ... -
Singleton Service in Weblogic Cluster
2012-03-21 00:12 711http://blog.csdn.net/mobicents/ ... -
Scheduled ThreadPool Executor suppressed or stopped after error happen
2012-03-20 16:54 1043ScheduledThreadPoolExecutor ... -
Bad version number in .class file
2012-01-27 00:35 895Bad version number in .class fi ... -
User Data Header in SMPP SUBMIT_SM
2012-01-25 22:30 2332SMPP 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 685What's saved in Object Referenc ... -
java.util.Properties: a subclass of java.util.Hashtable
2011-12-13 06:57 775I met a problem this afternoon ... -
Jmock usage
2011-12-02 05:37 0Discuss how Jmock working. -
Oracle Index Usage
2011-12-15 05:26 624Like a hash mapping for record' ... -
AOP(2):AOP与动态代理JDK Proxy and Cglib Proxy
2011-05-12 16:20 1026使用动态代理(JDK Proxy 或者Cglib Proxy) ... -
AOP(1):应用中的几个小故事
2011-05-09 21:49 975I had heared about AOP almost 7 ... -
异步系统设计:push vs pull
2011-05-02 23:59 1139今天讨论问题时,有个同事说系统A是主动去系统B里“拿”消息,我 ... -
Java Regular Expression (Java正则表达式)
2011-04-23 06:58 933In current Project, we need to ... -
XML Parser:DOM + XPath
2011-04-23 06:30 1201There are many kinds of XML Par ... -
File upload and download in Java Web Application.
2011-04-21 21:08 1715最近在项目中遇到一个下载文件的老问题。之所以说是老问题,因为在 ... -
Manage zip content using Java APIs
2011-04-21 18:14 1040JDK provide a set of utils to c ... -
Beanshell: how and where to use beanshell
2011-04-21 00:33 2095How to use beanshell beansh ... -
OXM: JAXB2.0 in JDK1.6
2011-04-20 22:53 12401.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的...
标题 "mybatis-generator-usage" 暗示我们要探讨的是关于MyBatis Generator的使用方法。MyBatis Generator是一款强大的工具,它能够自动生成MyBatis的映射文件、Java模型类以及DAO接口,极大地提高了开发效率。接...
##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. ...
Struts2还集成了许多其他框架,如Freemarker和Velocity模板引擎,以及iBatis和Hibernate持久化库。 **Hibernate框架** 是一个流行的Java ORM(对象关系映射)工具,它允许开发者用Java对象来操作数据库,减少了编写...
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 ...
- 绿色数据中心旨在提高能源效率,降低PUE(Power Usage Effectiveness),采用分布式技术、X86平台和本地存储,以减少能耗和环境影响。 - RDBMS架构与Hadoop架构的对比,揭示了如何通过计算与存储的融合和横向...
绿色数据中心则关注能源效率,衡量标准是PUE(Power Usage Effectiveness),即数据中心总能耗与IT设备能耗之比。降低PUE意味着更高的能源效率,更少的环境影响。绿色数据中心通过优化冷却系统、使用节能设备和实施...
您的支持帮助我们继续我们在 Velocity 和相关框架方面的工作。 #安装 meteor add xolvio:patcher#Usage 这个包设置了debugOnly标志,这意味着它不会被捆绑到应用程序中。 这也意味着您只能将其作为弱依赖引用,...
大数据的特点包括大量性(Volume)、高速性(Velocity)、多样性和价值密度低(Variety),以及真实性(Veracity)。大数据的出现对企业的决策制定、业务模式和创新能力产生了深远影响。 【数据中心建设】 数据中心...
understanding the usage of ABAQUS keywords is essential for modifying .inp files and performing finite element analysis. *AMPLITUDE:幅值关键字,用于定义幅值曲线的名称、类型和参数。该关键字在定义...
PUE(Power Usage Effectiveness)是衡量数据中心能源效率的指标,定义为数据中心整体能耗与IT设备能耗之比。而DCIE(Data Center Infrastructure Efficiency)是数据中心基础设施效率,表示数据中心用于运行IT设备...