Velocity中加载vm文件的三种方式

1Velocity中加载vm文件的三种方式 2 3velocitypropertiespath 4Velocity中加载vm文件的三种方式: 5 6方式一:加载classpath目录下的vm文件 7Properties p = new Properties(); 8p.put("file.resource.loader.class", 9"org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader"); 10Velocity.init(p); 11... 12Velocity.getTemplate(templateFile); 13 14 15方式二:根据绝对路径加载,vm文件置于硬盘某分区中,如:d://tree.vm 16Properties p = new Properties(); 17p.setProperty(VelocityEngine.FILE_RESOURCE_LOADER_PATH, "d://"); 18Velocity.init(p); 19... 20Velocity.getTemplate("tree.vm"); 21 22 23方式三:使用文本文件,如:velocity.properties,配置如下: 24#encoding 25input.encoding=UTF-8 26output.encoding=UTF-8 27contentType=text/html;charset=UTF-8 28不要指定loader. 29 30 31再利用如下方式进行加载 32Properties p = new Properties(); 33p.load(this.getClass().getResourceAsStream("/velocity.properties")); 34Velocity.init(p); 35... 36Velocity.getTemplate(templateFile); 37 38package com.study.volicity; 39 40import java.io.IOException; 41import java.io.StringWriter; 42import java.util.Properties; 43 44import org.apache.velocity.app.Velocity; 45import org.apache.velocity.Template; 46import org.apache.velocity.VelocityContext; 47 48public class Test { 49 50 51 public static void main(String args[]) throws IOException { 52 53 Properties pros = new Properties(); 54 pros.load(Test.class.getClassLoader().getResourceAsStream("velocity.properties")); 55 Velocity.init(pros); 56 VelocityContext context = new VelocityContext(); 57 58 context.put("name", "Velocity"); 59 context.put("project", "Jakarta"); 60 61 /* lets render a template 相对项目路径 */ 62 Template template = Velocity.getTemplate("/view/header.vm"); 63 64 StringWriter writer = new StringWriter(); 65 66 /* lets make our own string to render */ 67 template.merge(context, writer); 68 System.out.println(writer); 69 } 70 71}
点赞
收藏

评论区

加载中...

相关推荐

MySQL:[Err] 1292 - Incorrect datetime value: ‘0000-00-00 00:00:00‘ for column ‘CREATE_TIME‘ at row 1

文章目录问题用navicat导入数据时,报错:原因这是因为当前的MySQL不支持datetime为0的情况。解决修改sql\mode:sql\mode:SQLMode定义了MySQL应支持的SQL语法、数据校验等,这样可以更容易地在不同的环境中使用MySQL。全局s

Oracle 分组与拼接字符串同时使用

SELECTT.,ROWNUMIDFROM(SELECTT.EMPLID,T.NAME,T.BU,T.REALDEPART,T.FORMATDATE,SUM(T.S0)S0,MAX(UPDATETIME)CREATETIME,LISTAGG(TOCHAR(

MySQL部分从库上面因为大量的临时表tmp_table造成慢查询

背景描述Time:20190124T00:08:14.70572408:00User@Host:@Id:Schema:sentrymetaLast_errno:0Killed:0Query_time:0.315758Lock_

皕杰报表之UUID

​在我们用皕杰报表工具设计填报报表时,如何在新增行里自动增加id呢?能新增整数排序id吗?目前可以在新增行里自动增加id,但只能用uuid函数增加UUID编码,不能新增整数排序id。uuid函数说明:获取一个UUID,可以在填报表中用来创建数据ID语法:uuid()或uuid(sep)参数说明:sep布尔值,生成的uuid中是否包含分隔符'',缺省为

2020年前端实用代码段,为你的工作保驾护航

有空的时候,自己总结了几个代码段,在开发中也经常使用,谢谢。1、使用解构获取json数据let jsonData  id: 1,status: "OK",data: 'a', 'b';let  id, status, data: number   jsonData;console.log(id, status, number )

FLV文件格式

1.        FLV文件对齐方式FLV文件以大端对齐方式存放多字节整型。如存放数字无符号16位的数字300(0x012C),那么在FLV文件中存放的顺序是:|0x01|0x2C|。如果是无符号32位数字300(0x0000012C),那么在FLV文件中的存放顺序是:|0x00|0x00|0x00|0x01|0x2C。2.