一.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. POJ 3233 (矩阵)

    题意:对于矩阵A,求A^1 + ...... + A^k 按照矩阵十大经典题的思路大致做了下. 在k为奇数时:  A^( k / 2+1)+ 1) * (A^1 + ....... A^(k/2)) ...

  2. 10-8 uva1262密码

    题意:有两个图,每一列都存在的字母选作密码,就第k大的密码 思路: 找出各个位置上的密码, 假设: 第1个字母只能是{A,C,D,W}, 第2个字母只能是{B,O,P}, 第3个字母只能是{G,M,O ...

  3. *hdu 5536(字典树的运用)

    Input The first line of input contains an integer T indicating the total number of test cases. The f ...

  4. Gradle学习之基础篇

    一.gradle基础概念 Gradle是一个基于Apache Ant和Apache Maven概念的项目自动化构建工具.Gradle抛弃了基于各种繁琐的XML,使用一种基于Groovy的特定领域语言( ...

  5. Python中模块之sys的功能介绍

    sys模块的功能介绍 1. sys的变量 argv 命令行参数 方法:sys.argv 返回值:list 例如:test1.py文件中有两句语句1.import sys 2.print(sys.arg ...

  6. prop与attr的区别

    与prop一样attr也可以用来获取与设置元素的属性. 区别在于,对于自定义属性和选中属性的处理. 选中属性指的是 checked,selected 这2种属性 1. 对于自定义属性 attr能够获取 ...

  7. JS中怎样判断undefined(比较不错的方法)

    最近做项目碰到的问题.拿出来跟大家分享一下吧. 用servlet赋值给html页面文本框值后,用alert来弹出这个值.结果显示"undefined".所以我就自然的用这个值和字符 ...

  8. java底层学习

    额,马上就要面试了,Java的底层肯定是需要了解的.网上找了找java的底层文章,做个记号.java底层主要是类的加载.连接和初始化. 本文主要分为四个方面: (1)java底层概述 (2)new和n ...

  9. 一口一口吃掉Hibernate(七)——继承映射

    前几篇博文中讲到了常用的几种关联映射.其实hibernate中还有一种"省劲儿"的映射,那就是--"继承映射". 学了这么多的关系映射了,继承映射,从字面上也能 ...

  10. 数据结构之Trie树

    1. 概述 Trie树,又称字典树,单词查找树或者前缀树,是一种用于快速检索的多叉树结构,如英文字母的字典树是一个26叉树,数字的字典树是一个10叉树. Trie一词来自retrieve,发音为/tr ...