建立hello.vm内容如下:
Hello $name! Welcome to $site world!
main方法如下:
import java.io.File;
import java.io.StringWriter;
import org.apache.velocity.Template;
import org.apache.velocity.VelocityContext;
import org.apache.velocity.app.VelocityEngine;
public class HelloWorld{
public static void main( String[] args )throws Exception{
/* first, get and initialize an engine */
VelocityEngine ve = new VelocityEngine();
ve.init();
/* next, get the Template */
File file = new File("hello.vm");
System.out.println(file.exists());
Template t = ve.getTemplate( "hello.vm" );
/* create a context and add data */
VelocityContext context = new VelocityContext();
context.put("name", "Billy");
context.put("site", "http://www.sina.com");
/* now render the template into a StringWriter */
StringWriter writer = new StringWriter();
t.merge( context, writer );
/* show the World */
System.out.println( writer.toString() );
}
}
运行结果如下:
Hello Billy! Welcome to http://www.sina.com world!
分享到:
相关推荐
web开发的,Velocity,简单环境实例,已通过运行,
java velocity基于模版开发简单小例子
NULL 博文链接:https://javaocean.iteye.com/blog/256655
微软推出的分布式缓存方案velocity 这是我对velocity应用的简单demo 大家可以下载回来试下
JAVAEE Velocity例子工程,一个简单的Velocity例子,用的都是代码,没有用Velocity配置文件
一个很简单容易上手的struts2与velocity集成 实例;很方便初学者进入struts2与velocity集成 学习
SpringMVC3+velocity最简单配置例子,入门级的demo
提供给广大velocity学习爱好者借鉴,参考;
SpringMVC+ibatis+velocity整合例子,虽然比较简单。可以为没有配置好的同学作为参考。
NULL 博文链接:https://xutao5641745.iteye.com/blog/1667997
struts2+spring+velocity简单的扩展实例,下载下来就能运行。后续将整合各项技术。敬请期待。
用Velocity自己改装的jquery+json+springMVC+ibatis简单例子 希望能帮到大家
一个简单的velocity的例子,从这里你可以了解velocity的强大功能
velocity分页的例子,很简单,大家可以看看
一个简单的struts2 整合 velocity 模板的例子
本篇文章将通过一个简单显示用户信息的实例整合Spring mvc+mybatis+Maven+velocity+mysql. 一、.Maven工程目录 二、Spring mvc + mybatis +maven实现 1.Mysql数据库表数据
该项目由maven构建的web项目,实例简单,无数据库连接操作
spring+hibernate+velocity 架构的简单例子
花了所有CSDN积分收集来的Velocity资料集合: Velocity Java开发指南中文版 Velocity Web应用开发指南中文版 Velocity模板使用指南中文版 ...Struts与Velocity的简单集成 使用Velocity开发web程序