introduction of velocity
一.velocity 简介
基于java 的模板引擎,apache 旗下的开源软件项目。
目的在于隔离 表示层和业务逻辑层,当然现在做的不仅仅是这些。
二.应用场景
- web 应用程序:创建html页面,页面的动态信息有velocity框架来处理
意味着可以不使用JSP等动态语言 - 源代码生成:基于模板生成java,sql源代码
- email 生成:将邮件模板存储在文本文件
- xml转换:velocity 提供一个Ant 任务-Anakia,Anakia 读取xml文件,利用velocity 模板转换为所需的文档格式
三.基本语法
1.关键字以#开头
2.变量以$开头,变量类型是弱类型
3.定义函数
#macro(macroname arg1 arg2)
#end
调用
#macroname(arg1 arge)
4.#parse,#include
两者都是引用外部文件,
#parse会将引用的内容作为源码文件执行,会对代码进行解析
#include拷贝替换所有的文本内容
更多http://www.cnblogs.com/codingsilence/archive/2011/03/29/2146580.html
四.第一个项目—-场景1(web应用程序)
pre:
jar 包下载
http://velocity.apache.org/download.cgi?cm_mc_uid=56692902242514430865854&cm_mc_sid_50200000=1451871613
需要引入velocity-1.7.jar,以及lib包下面jar文件
VelocityTag
1.初始化VelocityEngine
VelocityEngine ve = new VelocityEngine();
// Velocity.java implements RuntimeConstants
// so you can use RuntimeConstants.RESOURCE_LOADER="resource.loader"
ve.setProperty(Velocity.RESOURCE_LOADER, "classpath");
ve.setProperty("classpath.resource.loader.class", ClasspathResourceLoader.class.getName());
ve.init();
2.关联模板文件
Template template = ve.getTemplate("velocity/firstVelocity.vm");
3.写入动态内容
VelocityContext context = new VelocityContext();
context.put("first", "fristVelocityExample");
4.输入到浏览器
PrintWriter pw = response.getWriter();
template.merge(context, pw);
代码访问github
introduction of velocity的更多相关文章
- Discrete.Differential.Geometry-An.Applied.Introduction(sig2008)笔记
-------------------------------------------------------------- Chapter 1: Introduction to Discrete D ...
- [转]DCM Tutorial – An Introduction to Orientation Kinematics
原地址http://www.starlino.com/dcm_tutorial.html Introduction This article is a continuation of my IMU G ...
- 【转】Velocity模板(VM)语言介绍
http://www.blogjava.net/caizh2009/archive/2010/08/20/329495.html Velocity是什么? Velocity是一个基于java的模板引擎 ...
- Introduction To Monte Carlo Methods
Introduction To Monte Carlo Methods I’m going to keep this tutorial light on math, because the goal ...
- [Java] 模板引擎 Velocity 随笔
Velocity 是一个基于 Java 的模板引擎. 本博文演示 Velocity 的 HelloWord 以及分支条件. HelloWord.vm,模板文件. templateDemo.java, ...
- Introduction to Parallel Computing
Copied From:https://computing.llnl.gov/tutorials/parallel_comp/ Author: Blaise Barney, Lawrence Live ...
- (转)Introduction to Gradient Descent Algorithm (along with variants) in Machine Learning
Introduction Optimization is always the ultimate goal whether you are dealing with a real life probl ...
- Introduction to Big Data with PySpark
起因 大数据时代 大数据最近太热了,其主要有数据量大(Volume),数据类别复杂(Variety),数据处理速度快(Velocity)和数据真实性高(Veracity)4个特点,合起来被称为4V. ...
- 《Apache Velocity用户指南》官方文档
http://ifeve.com/apache-velocity-dev/ <Apache Velocity用户指南>官方文档 原文链接 译文连接 译者:小村长 校对:方腾飞 Qui ...
随机推荐
- [Luogu 3835]【模板】可持久化平衡树
Description 您需要写一种数据结构(可参考题目标题),来维护一些数,其中需要提供以下操作(对于各个以往的历史版本): 插入x数 删除x数(若有多个相同的数,因只删除一个,如果没有请忽略该操作 ...
- [Luogu 2062]分队问题
Description 给定n个选手,将他们分成若干只队伍.其中第i个选手要求自己所属的队伍的人数大等于a[i]人. 在满足所有选手的要求的前提下,最大化队伍的总数. 注:每个选手属于且仅属于一支队伍 ...
- [USACO 07NOV]Cow Relays
Description For their physical fitness program, N (2 ≤ N ≤ 1,000,000) cows have decided to run a rel ...
- bzoj 1880: [Sdoi2009]Elaxia的路线
Description 最近,Elaxia和w的关系特别好,他们很想整天在一起,但是大学的学习太紧张了,他们 必须合理地安排两个人在一起的时间.Elaxia和w每天都要奔波于宿舍和实验室之间,他们 希 ...
- bzoj1926[Sdoi2010]粟粟的书架 二分 主席树
1926: [Sdoi2010]粟粟的书架 Time Limit: 30 Sec Memory Limit: 552 MBSubmit: 1064 Solved: 421[Submit][Stat ...
- django rest-framework 1.序列化 二
在上一节说了Serializers的使用类似Django的From,在Django中有From也有ModelFrom,Serializers也是有个ModelSerializers,下面在讲讲rest ...
- PHP查看本地文件夹及删除文件夹操作
查看文件夹(包括文件夹内所有的文件夹和文件) function descdir($dir){ if(is_dir($dir)){ if($dh=opendir($dir)){ while(($file ...
- 通过实例理解 RabbitMQ 的基本概念
先说下自己开发的实例. 最近在使用 Spring Cloud Config 做分布式配置中心(基于 SVN/Git),当所有服务启动后,SVN/Git 中的配置文件更改后,客户端服务读取的还是旧的配置 ...
- Spring使用webjar
注意事项 这玩意很简单,但是我们第一次搞就是搞不成功,为什么呢?因为我们都用的是idea或者eclipse编译.webjar只能在maven上才能打包,所以在使用时,记得maven-clean和mav ...
- easing--缓动函数--贝塞尔函数--圆盘转动抽奖应用
http://gsgd.co.uk/sandbox/jquery/easing/jquery.easing.1.3.js http://www.robertpenner.com/easing/penn ...