一.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的更多相关文章

  1. Discrete.Differential.Geometry-An.Applied.Introduction(sig2008)笔记

    -------------------------------------------------------------- Chapter 1: Introduction to Discrete D ...

  2. [转]DCM Tutorial – An Introduction to Orientation Kinematics

    原地址http://www.starlino.com/dcm_tutorial.html Introduction This article is a continuation of my IMU G ...

  3. 【转】Velocity模板(VM)语言介绍

    http://www.blogjava.net/caizh2009/archive/2010/08/20/329495.html Velocity是什么? Velocity是一个基于java的模板引擎 ...

  4. Introduction To Monte Carlo Methods

    Introduction To Monte Carlo Methods I’m going to keep this tutorial light on math, because the goal ...

  5. [Java] 模板引擎 Velocity 随笔

    Velocity 是一个基于 Java 的模板引擎. 本博文演示 Velocity 的 HelloWord 以及分支条件. HelloWord.vm,模板文件. templateDemo.java, ...

  6. Introduction to Parallel Computing

    Copied From:https://computing.llnl.gov/tutorials/parallel_comp/ Author: Blaise Barney, Lawrence Live ...

  7. (转)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 ...

  8. Introduction to Big Data with PySpark

    起因 大数据时代 大数据最近太热了,其主要有数据量大(Volume),数据类别复杂(Variety),数据处理速度快(Velocity)和数据真实性高(Veracity)4个特点,合起来被称为4V. ...

  9. 《Apache Velocity用户指南》官方文档

    http://ifeve.com/apache-velocity-dev/ <Apache Velocity用户指南>官方文档 原文链接   译文连接 译者:小村长  校对:方腾飞 Qui ...

随机推荐

  1. UVA1658:Admiral

    题意:给定一个有向带权图,求两条不相交(无公共点)的路径且路径权值之和最小,路径由1到v 题解:这题的关键就在于每个点只能走一遍,于是我们想到以边换点的思想,用边来代替点,怎么代替呢? 把i拆成i和i ...

  2. 17.10.31&11.01

    10.31模拟考试 Prob.1(AC)裸的矩阵幂 Prob.2(WA)(类似括号匹配求合法方案数) 卡特兰数的一个模型运用.可以推出一个式子(推导方法一个erge讲的,一个骚猪讲的) Prob.3( ...

  3. [POI2000] 最长公共子串

    给出几个由小写字母构成的单词,求它们最长的公共子串的长度. 任务 从文件中读入单词 计算最长公共子串的长度 输出结果到文件 输入 文件的第一行是整数 n,1<=n<=5,表示单词的数量.接 ...

  4. ANI功能分析

    1 ANI ANI(Adapt Noise Immunity)就是基于CCK错包率,和/或CCK错包率,自动调整抗扰等级,从而提高或降低灵敏度,达到提高整体性能的目标. 2 关键常量 firstep_ ...

  5. Docker 基础 : 镜像

    目录 获取镜像 查看镜像信息 搜索镜像 删除镜像 创建镜像 导出和导入镜像 上传镜像 总结 镜像是 Docker 的三大核心概念之一.Docker 运行容器前需要本地存在对应的镜像,如果本地没有对应的 ...

  6. HTTP Status Codes 查询表

    Web项目中经常会出现各种状态码,今天看到一个博客,挺不错,记录下来.

  7. div英文内容超过div长度

    添加css word-break: normal;word-wrap: break-word;

  8. JSON.parse()在火狐中的BUG

      //用sessionStorage解决load页面刷新问题 { //sessionStorage.removeItem("loadInfo"); var loadInfo=de ...

  9. ubuntu部署mipsel64交叉编译环境

    最近找到个不错的交叉工具链,据传能够编译mipsel64的程序,决定试试. 首先当然是安装环境: apt install -y gcc libncursesada3-dev 下载,解压,进入 三部曲: ...

  10. kafka Centos7.2 单机集群搭建

    前提是已经安装好了zk集群 1.下载  kafka_2.11-1.0.0.tgz  下载网址 http://kafka.apache.org/documentation.html 2.解压  tar ...