Spring MVC中VM页面使用自定义宏

在使用vm做为视图展示时,Spring框架本身提供了一些定义好的宏让开发者重用.如在spring.vm文件中,如页面表单绑定常用的宏:
#macro( springBind $path )
#if("$!springHtmlEscape" != "")
#set( $status = $springMacroRequestContext.getBindStatus($path, $springHtmlEscape) )
#else
#set( $status = $springMacroRequestContext.getBindStatus($path) )
#end
#end

而在实际项目中,开发者要定义很多自己的宏以使一些功能得到重用.如何让spring加载自定的宏文件呢.在以下配置中:

<bean id="velocityConfigurer"
class="org.springframework.web.servlet.view.velocity.VelocityConfigurer">
<property name="resourceLoaderPath">
<value>/WEB-INF/vm/</value>
</property>
<property name="configLocation" value="/WEB-INF/velocity.properties" />
</bean>

该属性configLocation设置了velocity属性配置文件的路径及文件名,.要想使用自定的宏,只需在velocity.properties文件中指定如下两项的值.
velocimacro.library = macros-default.vm
velocimacro.library.autoreload = true
而在这个文件macros-default.vm中,我们自定义的一些宏都可以放入其中.
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值