import java.io.StringWriter;
import org.apache.velocity.app.VelocityEngine;
import org.apache.velocity.Template;
import org.apache.velocity.VelocityContext;
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 */
Template t = ve.getTemplate( "hellosite.vm" );
/* create a context and add data */
VelocityContext context = new VelocityContext();
context.put("name", "sun");
context.put("site", "http://i.cn.yahoo.com/littlenewus/blog/p_3/");
/* now render the template into a StringWriter */
StringWriter writer = new StringWriter();
t.merge( context, writer );
/* show the World */
System.out.println( writer.toString() );
}
}
把velocity的包加到classpath 。。然后再写一个hellosite.vm 在里面有$name 和$site 就行了 不管了写什么叼东西。。
上面的代码也是从工作日志直接复制的 也应该能看懂吧 呵呵。。 这是velocity怎么叼模板的过程。
恩 ,当然在实际用的时候这些事情不用我们来做了 我们只需要怎么用velocity里面规定的访问机制就行了。
分享到:
相关推荐
该文档为velocity学习笔记,包含一些常见问题
关于velocity的学习资料,velocity教程和velocity用户手册
使用struts配置含有velocity的Web项目,并且成功跳转,并使用Velocity展示数据
Velocity学习资料,从网上找到的其中学习笔记由个人编写,希望大家借鉴,后续继续完善中。
Velocity教程
velocity学习笔记与struts2整合 velocity学习笔记与struts2整合 velocity学习笔记与struts2整合
Velocity用户指南旨在帮助页面设计者和内容提供者了解Velocity和其简单而又强大的脚本语言(Velocity Template Language (VTL))。本指南中有很多示例展示了用Velocity来讲动态内容嵌入到网站之中,但是所有的VTL ...
JAVA的Velocity语法学习 内涵《Velocity_java开发指南》《Java的模板引擎Velocity初体验》 以及所必须的jar ,和大家一块学习,很好哦
spring+ajax+velocity实现进度条上传。
使用velocity,静态页面分页的实现
使用velocity freemarke 模版实现页面静态化,有具体代码实现例子
Velocity实现模板
本课程的定位是velocity的系统教学课程 , 从基础到进阶 , 所以只要对velocity感兴趣 , 想系统学习velocity的开发人员都可以学习本课程 ! 学习本课程对你有如下要求 : l 有一定的JAVA编程基础(velocity engine要求) l...
velocity中文手册 velocity学习资料
Velocity中文学习指南
velocity语法
Velocity模板引擎Velocity模板引擎Velocity模板引擎Velocity模板引擎Velocity模板引擎Velocity模板引擎Velocity模板引擎Velocity模板引擎Velocity模板引擎Velocity模板引擎
spring3 mvc mybatis velocity登录功能的简单实现,主要是想用下mybatis和velocity
Velocity 的主要目标是通过模板生成格式文档. 因此, Velocity自身不提供任何Web相关的功能. 当你需要开发Web应用时, 需要一个框架来接收 HTTP请求和, 处理用户认证,执行业务逻辑调用,最后生成应答内容返回给客户端...
Velocity Velocity Velocity Velocity Velocity Velocity Velocity Velocity Velocity Velocity