您的位置:首页 > 其它

velocity使用--登录页面等某些特殊页面使用的模板与其他页面不同

2015-11-27 17:39 316 查看
场景:系统中的登录页面所使用的模板与其他普通页面使用的模板不同,或者是某些页面需要引用不同的模板时

1.springmvc配置视图解析器

<!-- 配置vm视图解析器 -->

<bean id="viewResolver"

class="org.springframework.web.servlet.view.velocity.VelocityLayoutViewResolver">

<property name="viewClass" value="org.springframework.web.servlet.view.velocity.VelocityLayoutView"/>

<!-- <property name="toolboxConfigLocation" value="/WEB-INF/classes/toolbox.xml"/> -->

<property name="contentType" value="text/html;charset=UTF-8" />

<property name="prefix" value=""/>

<property name="suffix" value=".vm" />

<property name="layoutUrl" value="layout/default.vm"></property>

<property name="layoutKey" value="layout"></property>

<property name="exposeSpringMacroHelpers" value="true" />

<property name="screenContentKey" value="screen_content" />

<property name="exposeRequestAttributes" value="true" /><!-- if open request Attributes-->

<property name="requestContextAttribute" value="rc"/><!-- request Attribute name-->

<property name="dateToolAttribute">

<value>dateTool</value>

</property>

<property name="numberToolAttribute">

<value>numberTool</value>

</property>

</bean>

解释:配置layoutUrl设定系统默认的模板路径

layoutKey设定模板文件键值,设定该值后就可以在vm文件中使用该键值设置模板路径,

screenContentKey表示指定vm文件显示位置

通过以上配置后普通页面velocity会自动套用layout/default.vm模板

如果登录页面需套用自己独特的模板则如下

可以在登录页面中添加:

#set($layout="login_layout.vm")

则登录页面将套用"login_layout.vm"模板
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: