spring中velocity的配置

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()
张三
渲染hello.vm文件
HashMap data = new HashMap();
String s = VelocityEngineUtils.mergeTemplateIntoString(velocityEngine,template, encode, data);
System.out.println(s);

输出结果为

hello
张三




  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值