一.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. USACO 2017 February Platinum

    第二次参加USACO 本来打算2016-2017全勤的 January的好像忘记打了 听群里有人讨论才想起来铂金组三题很有意思,都是两个排列的交叉对问题 我最后得分889/1000(真的菜) T1.W ...

  2. poj2449 (第k条最短路)

    题意:求n个点中,a到b的第k条最短路 思路: 用最短路求出估价函数的h,再在搜索过程中记录g,利用A*求出 最开始想到的便是A*和最短路,但是脑子抽了,居然一个一个去求- -,TL了后才发现可以倒着 ...

  3. hdu1698 线段树区间更新

    Just a Hook Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Tota ...

  4. hdu5634 BestCoder Round #73 (div.1)

    Rikka with Phi  Accepts: 5  Submissions: 66  Time Limit: 16000/8000 MS (Java/Others)  Memory Limit: ...

  5. 如何导入python中的模块

    作为一名新手Python程序员,你首先需要学习的内容之一就是如何导入模块或包.但是我注意到,那些许多年来不时使用Python的人并不是都知道Python的导入机制其实非常灵活.在本文中,我们将探讨以下 ...

  6. python学习之装饰器-

    python的装饰器 2018-02-26 在了解python的装饰器之前我们得了解python的高阶函数 python的高阶函数我们能返回一个函数名并且能将函数名作为参数传递 def outer() ...

  7. PTA 旅游规划(25 分)

    7-10 旅游规划(25 分) 有了一张自驾旅游路线图,你会知道城市间的高速公路长度.以及该公路要收取的过路费.现在需要你写一个程序,帮助前来咨询的游客找一条出发地和目的地之间的最短路径.如果有若干条 ...

  8. mysql 拼接

    SELECT  RTRIM(CONCAT(belong_master_ip ,'(',host_name,')')) AS cloudIP  FROM `cloud_master_cfg`

  9. java线程与进程

    Java线程与进程 进程与线程的关系 进程里面至少有一个线程,进程间的切换会有较大的开销 线程必须依附在进程上,同一进程共享代码和数据空间 多线程的优势 多线程可以达到高效并充分利用cpu 线程使用的 ...

  10. Servlet生命周期与工作原理(转载)

    Servlet生命周期分为三个阶段: 1,初始化阶段  调用init()方法 2,响应客户请求阶段 调用service()方法 3,终止阶段 调用destroy()方法 Servlet初始化阶段: 在 ...