spring中velocity的配置
2013-10-11 10:24
393 查看
spring中velocity的配置
1velocity.properties文件的配置
runtime.log.invalid.reference = true input.encoding=UTF-8 output.encoding=UTF-8 ---------------------------------------------------------- directive.foreach.counter.name = velocityCount directive.foreach.counter.initial.value = 1 directive.include.output.errormsg.start = <!-- include error : directive.include.output.errormsg.end = see error log --> # ---------------------------------------------------------------------------- # P A R S E P R O P E R T I E S # ---------------------------------------------------------------------------- directive.parse.max.depth = 10 # ---------------------------------------------------------------------------- # VELOCIMACRO PROPERTIES # ---------------------------------------------------------------------------- # global : name of default global library. It is expected to be in the regular # template path. You may remove it (either the file or this property) if # you wish with no harm. # ---------------------------------------------------------------------------- # dev-changes by Marino webapp.resource.loader.cache = true webapp.resource.loader.modificationCheckInterval = 5 velocimacro.library.autoreload = false velocimacro.library = /WEB-INF/VM_global_library.vm velocimacro.permissions.allow.inline = true velocimacro.permissions.allow.inline.to.replace.global = false velocimacro.permissions.allow.inline.local.scope = false velocimacro.context.localscope = false # ---------------------------------------------------------------------------- # INTERPOLATION # ---------------------------------------------------------------------------- # turn off and on interpolation of references and directives in string # literals. ON by default :) # ---------------------------------------------------------------------------- runtime.interpolate.string.literals = true # ---------------------------------------------------------------------------- # RESOURCE MANAGEMENT # ---------------------------------------------------------------------------- # Allows alternative ResourceManager and ResourceCache implementations # to be plugged in. # ---------------------------------------------------------------------------- resource.manager.class = org.apache.velocity.runtime.resource.ResourceManagerImpl resource.manager.cache.class = org.apache.velocity.runtime.resource.ResourceCacheImpl # ---------------------------------------------------------------------------- # user common # ---------------------------------------------------------------------------- userdirective=
着重注意的是velocimacro.library,其实路径为项目的根目录,这个文件主要配置的是被项目全局使用的volocity宏。
2 spring中的配置
<bean id="velocityEngine" class="org.springframework.ui.velocity.VelocityEngineFactoryBean"> <property name="resourceLoaderPath" value="/" /> <property name="configLocation">
//加载上面的配置文件 <value>/WEB-INF/velocity.properties</value> </property> </bean>
3 示例
VM_global_library.vm拥有宏#macro(hello) hello #end
单个hello.vm文件为
#hello()[code]张三
渲染hello.vm文件
HashMap data = new HashMap(); String s = VelocityEngineUtils.mergeTemplateIntoString(velocityEngine,template, encode, data); System.out.println(s);
输出结果为
hello[code]张三
相关文章推荐
- spring 在web项目中的一些基本配置
- 让x 的值在0到9之间循环变化
- Java输入输出流详解
- spring中的acegi
- Java多线程--线程常用操作方法
- spring mvc 和 struts2的比较
- 安装rJava包失败处理方法
- java 读properties中文乱码问题
- struts2的完整的struts.xml骨架
- Dijkstra和floyd——求单源点最短路径
- 堆排序 java
- Build path entry is missing:org.eclipse.jdt.launching.JRE_CONTAINER/
- ubuntu13.04下安装jdk7
- ubuntu安装jdk全过程(仅供参考)
- hibernate spring 事务配置
- Can't OPEN Eclipse
- eclipse在Ubuntu 13.04下的安装过程及问题小记
- 怎么修改MyEclipse 默认workspace
- Java版的Quartz表达式生成器,同时适用于Quartz.net(免费下载)
- 关于JAVA多线程同步