一.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 3243]Clever Y

    Description Little Y finds there is a very interesting formula in mathematics: XY mod Z = K Given X, ...

  2. [HNOI 2016]网络

    Description 一个简单的网络系统可以被描述成一棵无根树.每个节点为一个服务器.连接服务器与服务器的数据线则看做 一条树边.两个服务器进行数据的交互时,数据会经过连接这两个服务器的路径上的所有 ...

  3. [PA 2014]Kuglarz

    Description 魔术师的桌子上有n个杯子排成一行,编号为1,2,…,n,其中某些杯子底下藏有一个小球,如果你准确地猜出是哪些杯子,你就可以获得奖品.花费c_ij元,魔术师就会告诉你杯子i,i+ ...

  4. [Tjoi2013]最长上升子序列

    Description 给定一个序列,初始为空.现在我们将1到N的数字插入到序列中,每次将一个数字插入到一个特定的位置.每插入一个数字,我们都想知道此时最长上升子序列长度是多少? Input 第一行一 ...

  5. hdu 4267 线段树间隔更新

    A Simple Problem with Integers Time Limit: 5000/1500 MS (Java/Others)    Memory Limit: 32768/32768 K ...

  6. [APIO/ctsc2007]

    A.风铃 给一棵二叉树,叶子结点是玩具,为使你的弟弟满意,你需要选一个满足下面两个条件的风铃: (1) 所有的玩具都在同一层(也就是说,每个玩具到天花板之间的杆的个数是一样的)或至多相差一层.(2) ...

  7. Tensorflow 免费中文视频教程,开源代码,免费书籍.

    Free-Tensorflow Tensorflow 免费中文视频教程,开源代码,免费书籍. 官方教程 官方介绍 https://tensorflow.google.cn/ 安装教程 https:// ...

  8. React Suite v3.0 正式版发布

    React Suite v3.0 正式版发布 相信很多人会好奇,React Suite 是什么? React Suite 是 HYPERS 前端团队和 UX 团队开源的一套基于 React 的 UI ...

  9. jquery easyui datagrid设置行样式 不可删除某行

    rowStyler: function (index,row) { if (parseInt(row.ksrs) > 0) { return 'color:red'; } }, onLoadSu ...

  10. 轻松理解AOP问题

    先说一个Spring是什么吧,大家都是它是一个框架,但框架这个词对新手有点抽象,以致于越解释越模糊,不过它确实是个框架的,但那是从功能的角度来定义的,从本质意义上来讲,Spring是一个库,一个Jav ...