本地应用velocity
1、建一个工程,把包导入(这里应用的1.6)
2、创建一个含有main方法的类
import java.io.IOException;
import java.io.StringWriter;
import org.apache.velocity.Template;
import org.apache.velocity.VelocityContext;
import org.apache.velocity.app.VelocityEngine;
import org.apache.velocity.exception.MethodInvocationException;
import org.apache.velocity.exception.ParseErrorException;
import org.apache.velocity.exception.ResourceNotFoundException;
public class TestTemplateTheory {
/**
* @param args
*/
public static void main(String[] args) {
try {
//初始化velocity引擎
VelocityEngine ve = new VelocityEngine();
ve.init();
//獲取模板
Template template = ve.getTemplate("test1.vm");
//填充數據
VelocityContext velocityContext = new VelocityContext();
velocityContext.put("myname", "姚明");
velocityContext.put("yourname", "麦迪");
//合并數據
StringWriter writer = new StringWriter();
template.merge( velocityContext, writer );
//顯示
System.out.println(writer.toString());
System.out.println(template);
} catch (ResourceNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (ParseErrorException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (MethodInvocationException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
3、和main类同一个目录下见一个模板文件test1.vm
内容如下
<html>
<body>
#set($foo = "velocity")
Hello $foo world;
My name is $myname
Your name is $yourname
</body>
</html>
4、运行main方法,控制台会打印出生成的html内容
<html>
<body>
Hello velocity world;
My name is 姚明
Your name is 麦迪
</body>
</html>
分享到:
相关推荐
赠送jar包:velocity-engine-core-2.3.jar; 赠送原API文档:velocity-engine-core-2.3-javadoc.jar; 赠送源代码:velocity-engine-core-2.3-sources.jar; 赠送Maven依赖信息文件:velocity-engine-core-2.3.pom;...
赠送jar包:velocity-engine-core-2.3.jar 赠送原API文档:velocity-engine-core-2.3-javadoc.jar 赠送源代码:velocity-engine-core-2.3-sources.jar 包含翻译后的API文档:velocity-engine-core-2.3-javadoc-...
赠送jar包:velocity-tools-generic-3.1.jar; 赠送原API文档:velocity-tools-generic-3.1-javadoc.jar; 赠送源代码:velocity-tools-generic-3.1-sources.jar; 赠送Maven依赖信息文件:velocity-tools-generic-...
velocity-tools-2.0.jar velocity-tools-2.0.jar velocity-tools-2.0.jar velocity-tools-2.0.jar velocity-tools-2.0.jar
velocity-engine-core-2.1.jar
赠送jar包:velocity-tools-generic-3.1.jar 赠送原API文档:velocity-tools-generic-3.1-javadoc.jar 赠送源代码:velocity-tools-generic-3.1-sources.jar 包含翻译后的API文档:velocity-tools-generic-3.1-...
还在为找不到jar文件烦心吗,不用了到我空间来有你想要的,持续更新。。。 velocity-1.5.jar,velocity-1.6.2-dep.jar,velocity-tools-1.3.jar
velocity 2.0 包需要的 jar 包 官方下载的,测试过了,可以运行 Demo 网上都有,关键几行代码: // ve.setProperty(RuntimeConstants.RESOURCE_LOADER, "file"); // 按文件加载 // ve.init(); // Template t = ...
velocity-dep-1.4.jar velocity-dep-1.4.jar
velocity-1.7,包含jar包以及全部的依赖
• commons-collections-3.2.jar • velocity-1.4.jar • velocity-tools-view-1.2.jar • avalon-logkit-2.1.jar
gradle-velocity-plugin.zip,速度预处理器的梯度插件。速度预处理器的梯度插件。
velocity-1.7-dep.jar.zip velocity-1.7-dep.jar.zip velocity-1.7-dep.jar.zip
velocity(1.1---1.5所有包) velocity-1.4 velocity-1.5 velocity-dep-1.3.1 velocity-tools-1.1 velocity-tools-generic-1.2 velocity-tools-view-1.2 velocity-tools-view-1.3
velocity-tools-view-1.4.jar
velocity-tools-1.4.jar
当Velocity应用于web开发时,界面设计人员可以和java程序开发人员同步开发一个遵循MVC架构的web站点,也就是说,页面设计人员可以只关注页面的显示效果,而由java程序开发人员关注业务逻辑编码。Velocity将java代码...
velocity-tools-view-2.0.jar
赠送jar包:velocity-1.7.jar; 赠送原API文档:velocity-1.7-javadoc.jar; 赠送源代码:velocity-1.7-sources.jar; 包含翻译后的API文档:velocity-1.7-javadoc-API文档-中文(简体)版.zip 对应Maven信息:...
注:下文中的 *** 代表文件名中的组件名称。 # 包含: 中文-英文对照文档:【***-javadoc-API文档-中文(简体)-英语-对照版.zip】 jar包下载地址:【***.jar下载地址(官方地址+国内镜像地址).txt】 ...