`
wanxiaotao12
  • 浏览: 456295 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

Apache Velocity简单例子

 
阅读更多

http://jakarta.apache.org/site/binindex.cgi上下载Velocity 包, 使用jar包:velocity-1.7.jar、avalon-logkit-2.1.jar、commons-collections-3.2.1.jar、commons-lang-2.4.jar、commons-logging-1.1.jar

1、Java类

package com.velocity;

import java.io.StringWriter;

import org.apache.velocity.Template;
import org.apache.velocity.VelocityContext;
import org.apache.velocity.app.VelocityEngine;

public class HelloWorld {

	/**
	 * @param args
	 */
	public static void main(String[] args) throws Exception {
		// 初始化并取得Velocity引擎
		VelocityEngine ve = new VelocityEngine();

		ve.init();
		// 取得velocity的模版,放到工程名下一级目录
		Template template = ve.getTemplate("hellovelocity.vm");
		// 取得velocity的上下文context
		VelocityContext context = new VelocityContext();
		// 把数据填入上下文
		context.put("name", "zhangsan");
		// 输出流
		StringWriter writer = new StringWriter();
		// 转换输出
		template.merge(context, writer);
		System.out.println(writer.toString());

	}

}

 2、hellovelocity.vm

 

Welcome  $name 

 

 

参考:http://www.iteye.com/topic/135506

分享到:
评论

相关推荐

    stillness:与 Apache Velocity 语法相同的提取模板引擎

    寂静与 Apache Velocity 语法相同的提取模板引擎。基本理念通过尝试将模板与格式化文本进行匹配来填充 Apache Velocity 上下文(又名字符串 -> 对象映射)。调用例子: import stillness.Stillness;import stillness...

    Velocity入门例子

    Apache-Velocity-java

    Apache click

    页面提供一种简单的线程安全的编程环境,为每次servlet 请求创建一个新页面实例。 可能最好的方式就是通过一些例子来看Click 如何工作。(这些例子在http://click.avoka.com/click-examples/ 的“intro Examples” ...

    apache click-2.3.0框架 例子(1)

    非常简单和易用,一般的开发人员在一天内就可以上手使用。 主要的特点包括: * 易学 * 面向组件和页面的设计 * 基于事件的编程模型 * 性能非常好 * 自动的表单生成以及客户端、服务器端数据验证 * 支持 ...

    sbt-velocity:基于Apache Velocity模板的SBT生成器插件

    例子:开始吧此插件需要SBT 0.13+。 您需要更新project/plugins.sbt 。 resolvers ++ = Seq ( " Tatami Releases " at " https://raw.github.com/cchantep/tatami/master/releases " )addSbtPlugin( " cchantep " %...

    实战STRUTS 电子书

    Struts是由Apache软件基金会支持的开源软件。 本书完整介绍了Struts框架结构,涵盖了设计、数据校验、数据库访问、动态页面生成、本地化、Struts配置以及其他一些重要的方面。书中还介绍了如何同时使用JSP标签和...

    Struts2入门教程(全新完整版)

    一、准备工作及实例 3 1.解压struts-2.1.6-all.zip 3 2.六个基本包 3 3.初识struts2配置文件 4 (1).web.xml文件 4 (2).struts.xml文件 4 (3).struts.properties(参default.properties) 4 (4)struts-...

    struts2 学习例子

    包括最常用的jsp页面,也可以说Velocity和FreeMarker等模板技术中的使用 2.Struts2分类 (1)UI标签:(User Interface, 用户界面)标签,主要用于生成HTML元素标签,UI标签又可分为表单标签非表单标签 (2)非UI...

    Struts in Action 中文版

    产品,包括Tomcat, Ant, 和 Velocity。 开始的代码基础从 2000 年5 月开始开发,直到2001 年6 月,1.0 版本发布。有 30 多个开发者 参与进来,并有数千人参与到讨论组中。Struts 代码基础由一个志愿者团队来管理。到...

    Struts2属性文件详解

    该属性指定整合Spring框架时,是否缓存Bean实例,该属性只允许使用true和false两个属性值,它的默认值是true.通常不建议修改该属性值. struts.objectTypeDeterminer 该属性指定Struts 2的类型检测机制, 通常支持tiger...

    Maven权威指南 很精典的学习教程,比ANT更好用

    下载本章的例子 3.2. 创建一个简单的项目 3.3. 构建一个简单的项目 3.4. 简单的项目对象模型 (Project Object Model) 3.5. 核心概念 3.5.1. Maven插件和目标 (Plugins and Goals) 3.5.2. Maven生命周期 ...

    SpringBoot Web项目案例视频课程

    其设计目标是开发迅速、轻量级、易扩展等核心框架:Spring Framework安全框架:Apache Shiro视图框架:SpringMVC持久层框架:MyBatis定时器:Quartz数据库连接池:Druid日志管理:Logback页面交互:Vue前后端分离:Swagger...

    Spring-Reference_zh_CN(Spring中文参考手册)

    Apache OJB 2.7.1.5. iBatis 2.8. 更新的样例应用 2.9. 改进的文档 I. 核心技术 3. 控制反转容器 3.1. 简介 3.2. 容器和bean的基本原理 3.2.1. 容器 3.2.1.1. 配置元数据 3.2.2. 实例化容器 3.2.2.1. 组成基于XML...

    浅谈PySpark SQL 相关知识介绍

    大数据除了体积(Volume)和速度(velocity)外,数据的多样性(variety)和准确性(veracity)也是大数据的一大特点。让我们详细讨论体积、速度、多样性和准确性。这些也被称为大数据的4V特征。 1.1 Volume 数据体积(Volume...

    外文翻译 stus MVC

    Tags are one of the things that make Struts unique compared to other frameworks like Velocity. Note: "Think thin" when extending the Action class. The Action class should control the flow and not ...

    基于jbpm与activiti的工作流平台技术架构介绍

    BPMX3提供了基于BPMN2标准的流程管理,包括流程版本变量,流程节点表单设置,表单的权限设置,流程任务通知,催办,代办,转化,并行会签、串行会签、补签,子流程,同步任务,多实例任务,人工任务、消息任务、邮件...

Global site tag (gtag.js) - Google Analytics