Velocity默认是加载文件系统中的模板,如果希望加载classpath下的模板的话,需要更换他的加载器
Properties properties=new Properties(); //设置velocity资源加载方式为class properties.setProperty("resource.loader", "class"); //设置velocity资源加载方式为file时的处理类 properties.setProperty("class.resource.loader.class", "org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader"); VelocityEngine ve = new VelocityEngine(properties);
默认情况是加载文件系统
VelocityEngine ve = new VelocityEngine();
//设置参数
ve.setProperty(Velocity.FILE_RESOURCE_LOADER_PATH, templatepath);//加载文件系统
另附完整代码
Properties properties=new Properties(); //设置velocity资源加载方式为class properties.setProperty("resource.loader", "class"); //设置velocity资源加载方式为file时的处理类 properties.setProperty("class.resource.loader.class", "org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader"); VelocityEngine ve = new VelocityEngine(properties); //设置参数 // ve.setProperty(Velocity.FILE_RESOURCE_LOADER_PATH, templatepath); //处理中文问题 ve.setProperty(Velocity.INPUT_ENCODING,"utf-8"); ve.setProperty(Velocity.OUTPUT_ENCODING,"utf-8"); try { //初始化模板 ve.init(); //Velocity模板的名称 Template template = ve.getTemplate(templatename,"utf-8"); Writer mywriter = new PrintWriter(outfile,"utf-8"); template.merge(vc, mywriter); mywriter.flush(); mywriter.close(); } catch (Exception e) { e.printStackTrace(); logger.error("写模板文件"+templatename+"失败", e); throw e; }
相关推荐
Velocity模板引擎Velocity模板引擎Velocity模板引擎Velocity模板引擎Velocity模板引擎Velocity模板引擎Velocity模板引擎Velocity模板引擎Velocity模板引擎Velocity模板引擎
Velocity模板实例 Velocity模板实例 Velocity模板实例 Velocity模板实例
Velocity.js 是velocity模板语法的javascript实现。Velocity 是基于Java的模板... 浏览器使用支持模板之间相互引用,依据kissy模块加载机制 三个Helper,友好的数据模拟解决方案 Vim Syntax 标签:Velocity
Spring Boot项目 自动生成数据表模板,包括:Mapper、Mapper.xml、Service、Controller
Velocity模板(VM)语言介绍,简单的介绍,方便入门!
SpringBoot集成Mybatis,velocity模板
Velocity实现模板
velocity-web模板工具, 参考:http://blog.csdn.net/nature_fly088/article/details/52497779 和http://www.ibm.com/developerworks/cn/java/j-lo-velocity1/
Jsp结合Velocity实现依据Word模板文件生成对应数据文件,操作非常灵活,方便。
Velocity模板入门简单DEMO, 代码有注解;
Velocity模板技术语法详细介绍,包括很详细的示例代码 1.变量………………………………………………………………………………1 2.循环………………………………………………………………………………2 3.条件语句...
velocity是一款除JSP以外的另一款模板引擎,也许很多地方比常规的JSP更加好,或者说它这种模板引擎是基于常规JSP与一些标签整合后。 zip包中有两个jar包,提供使用。
本课程从velocity engine也就是velocity引擎开始, 先讲解velocity的基本使用以及基础语法 , 然后再讲解velocity 的进阶内容velocity Tools , 以及velocity作为web项目的视图改如何使用 , 每一部分都会有一个综合案例...
模板:velocity和freemarker的比较模板:velocity和freemarker的比较
Velocity模板解析,通过Velocity模板自动替换表达式中的变量
velocity模板访问velocity模板访问velocity模板访问
史上最全Velocity模板使用指南中文版,适合初学者读阅
NULL 博文链接:https://vipshow.iteye.com/blog/1778614