SiteMesh2-sitemesh.xml的ParameterDecoratorMapper映射器的用法
继续使用上一章http://www.cnblogs.com/EasonJim/p/7086916.html的例子,改造成使用ParameterDecoratorMapper映射器的方法,这个映射器不需要通过匹配URL和在页面上写模板路径去实现,只需要通过URL上传入指定参数即可。
修改配置如下:
1、sitemesh.xml引入ParameterDecoratorMapper映射器
<sitemesh>
<property name="decorators-file" value="/WEB-INF/decorators.xml"/>
<excludes file="${decorators-file}"/> <page-parsers>
<parser content-type="text/html" class="com.opensymphony.module.sitemesh.parser.HTMLPageParser" />
</page-parsers>
<decorator-mappers>
<mapper class="com.opensymphony.module.sitemesh.mapper.PageDecoratorMapper">
<param name="property.1" value="meta.decorator" />
<param name="property.2" value="decorator" />
<!-- 注意这一行指定<meta/>标签的 name 属性作为PageDecorator的识别符号 -->
<param name="property.3" value="meta.theme" />
</mapper>
<mapper class="com.opensymphony.module.sitemesh.mapper.ParameterDecoratorMapper"/>
<mapper class="com.opensymphony.module.sitemesh.mapper.FrameSetDecoratorMapper"/>
<mapper class="com.opensymphony.module.sitemesh.mapper.PrintableDecoratorMapper">
<param name="decorator" value="printable" />
<param name="parameter.name" value="printable" />
<param name="parameter.value" value="true" />
</mapper>
<mapper class="com.opensymphony.module.sitemesh.mapper.FileDecoratorMapper"/>
<mapper class="com.opensymphony.module.sitemesh.mapper.ConfigDecoratorMapper">
<param name="config" value="${decorators-file}" />
</mapper>
</decorator-mappers>
</sitemesh>
2、新建test2.jsp页面,这个页面无需写任何模板
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title></title>
</head>
<body>
<h1>Test2</h1>
</body>
</html>
3、访问URL变成http://localhost:8080/test1/test2.jsp?decorator=basic-theme


而如果URL没有参数,那么会变成原始页面

4、为URL后面的参数指定自定义的参数名,修改sitemesh.xml中映射器的写法
<mapper class="com.opensymphony.module.sitemesh.mapper.ParameterDecoratorMapper">
<param name="decorator.parameter" value="theme"/>
</mapper>
访问URL变成:http://localhost:8080/test1/test2.jsp?theme=basic-theme
<mapper class="com.opensymphony.module.sitemesh.mapper.ParameterDecoratorMapper">
<param name="decorator.parameter" value="theme"/>
<param name="parameter.name" value="confirm"/>
<param name="parameter.value" value="true"/>
</mapper>
增加了两个参数,那么访问将变成访问URI时:test2.jsp?theme=basic-theme&confirm=true将映射装饰器basic-theme。那里的URI是test2.jsp?theme=basic-theme和test2.jsp?theme=basic-theme&confirm=false不会返回任何装饰器。
也就是说在访问时增加确认参数。
测试工程:https://github.com/easonjim/5_java_example/tree/master/sitemesh/test3
参考:
SiteMesh2-sitemesh.xml的ParameterDecoratorMapper映射器的用法的更多相关文章
- SiteMesh2-sitemesh.xml的PageDecoratorMapper映射器的用法
继上一章http://www.cnblogs.com/EasonJim/p/7083165.html中使用的例子中,是通过decorators.xml文件通过URL匹配进行转换的. 而下面这种方法是通 ...
- SiteMesh2-sitemesh.xml的其它映射器的用法
在sitemesh.xml中做常用的三个映射器,总结如下: 映射器元素的顺序确定优先级.良好的应用程序应使用以下顺序, Parameter query = ParameterDecoratorMapp ...
- SiteMesh2-sitemesh.xml的ConfigDecoratorMapper映射器的用法
继上一次的示例工程http://www.cnblogs.com/EasonJim/p/7083165.html,使用的就是ConfigDecoratorMapper映射器,通过指定目录下的页面,都同一 ...
- Java Persistence with MyBatis 3(中文版) 第三章 使用XML配置SQL映射器
关系型数据库和SQL是经受时间考验和验证的数据存储机制.和其他的ORM 框架如Hibernate不同,MyBatis鼓励开发者可以直接使用数据库,而不是将其对开发者隐藏,因为这样可以充分发挥数据库服务 ...
- Mybatis基于XML配置SQL映射器(二)
Mybatis之XML注解 之前已经讲到通过 mybatis-generator 生成mapper映射接口和相关的映射配置文件: 下面我们将详细的讲解具体内容 首先我们新建映射接口文档 sysUse ...
- 深入理解MyBatis的原理(四):映射器的用法
前言:继续深入学习 mybatis 的用法及原理,还是先会用再学习原理. 映射器的主要元素有:select.insert.update.delete.parameterMap(即将被删除,不建议使用) ...
- MyBatis学习笔记3--使用XML配置SQL映射器
<resultMap type="Student" id="StudentResult"> <id property="id&quo ...
- (三)使用XML配置SQL映射器
SqlSessionFactoryUtil.java package com.javaxk.util; import java.io.IOException; import java.io.Input ...
- mybatis 基于xml 配置的映射器
cache 给命名空间的缓存配置 cache-ref 其他命名空间缓存配置的引用 resultMap 描述如何从数据库结果集中来加载对象 <!--column不做限制,可以为任意表的字段,而p ...
随机推荐
- 转 MySQL数据库基础
http://lib.csdn.net/article/mysql/57883 1 数据库基础 一.数据库与数据库管理系统 1.数据库(DB):存放数据的仓库,从广义来说,数据不仅包括数字,还包括了文 ...
- oracle多语言环境下to_date时间转换问题
现象:在多语言环境下使用过oracle的同学想必都遇到过这样一个问题, date_v date; date_v := to_date('2010/11/16');--或'2010/11/16' 同一个 ...
- [ Nowcoder Contest 175 #B ] 区间
\(\\\) \(Description\) 给出一个长度为\(N\)的序列\(A[1]...A[N]\),定义一个合法区间 \([L,R]\) 当且仅当区间\(GCD\) 在这个区间内,求最长合法区 ...
- C++学习笔记(一)之指针
指向指针的引用 ; int * p; int *&r = p; //r为对指针p的引用 r = &i; //r为对p的引用,故对r赋值即将p指向i *r = ; //更新i的值 通过* ...
- [iOS]查看苹果支持的所有字库
有时候,在开发的时候,想换个字体更加优雅的显示.但是不知道苹果本身到底支持了那些字体,怎么办? 没关系,打开这个网址:http://iosfonts.com/ 所见即所得,非常方便,而且还表明了从那个 ...
- sql的for update
欢迎大家吐槽 oracle行级共享锁 通常是通过select … from for update语句添加的,同时该方法也是我们用来手工锁定某些记录的主要方法.比如,当我们在查询某些记录的过程中,不希望 ...
- ANNOTATION and analyse hello1.java
一.What is annotation? annotation的中文意思就是注解,注释的意思.注解也属于一种类型.它是在 Java SE 5.0 版本中开始引入的概念.它的形式跟接口很类似,不过前面 ...
- Analysis of container and Injection in Java, their history and future.
Container: 发展历程: 2000 年的时候 FreeBSD 开发了一个类似于 chroot 的容器技术 Jails,这是最早期,也是功能最多的容器技术.Jails 英译过来是监狱的意思,这个 ...
- (独孤九剑)--MySQL入门
:[一]概论 (1)什么是 MySQL? 一种关系型开源数据库,定义了存储信息的结构. 在数据库中,存在着一些表.类似 HTML 表格,数据库表含有行.列以及单元. 在分类存储信息时,数据库非常有用. ...
- 框架学习八:二维码(Zxing)
本文转自夏神:http://blog.csdn.net/xiaanming/article/details/10163203 一.用什么 二维码扫描用的google的开源框架Zxing. 二.下载 地 ...