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"模板
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"模板
相关文章推荐
- 逻辑斯谛回归与最大熵模型
- mysql 授权 user@'%' 为什么登陆的时候localhost 不行呢???
- Android Studio 和 Gradle的那些事儿
- ARM汇编指令集4
- 验证组件——FluentValidation
- 检测网络连接是否正常的方法
- ubuntu下终端操作MySql数据库的命令
- Linux内核的抽象结构
- CCBPM节点访问规则与绑定人员的关联
- 树莓派警署无线AP
- Sqlite数据库中"未处理SQLiteException"问题
- android项目自定义组合控件
- 设置样式:字体颜色和背景颜色
- IplImage中的widthStep大小计算及原理
- iOS App Archive & Generic Xcode Archive
- iOS开发笔记- Swift基本语法
- 随机产生字符串
- springmvc配置servlet的拦截形式/*和/的区别
- adb详细介绍以及常用adb命令
- 百度地图API三:实时轨迹动态展现