sitemesh应用Decorator模式

简介:

sitemesh应用Decorator模式,用filter截取request和response,把页面组件head,content,banner结合为一个完整的视图。通常我们都是用include标签在每个jsp页面中来不断的包含各种header, stylesheet, scripts and footer,现在,在sitemesh的帮助下,我们可以简单完成不同请求的界面视图。

1、在decorators.xml中设置模版

<?xml version="1.0" encoding="UTF-8"?>
<decorators defaultdir="/WEB-INF/views">
    
    <!-- 默认装饰页面, 在需要装饰的页面增加<meta name="decorator" content="default"/> -->
    <decorator name="blank" page="layouts/blank.jsp" />
    <decorator name="default" page="layouts/default.jsp" />
    
    <!-- CMS基础主题装饰页面 -->
    <decorator name="cms_default_basic" page="modules/cms/front/themes/basic/layouts/default.jsp" />
    <decorator name="cms_default_weixin" page="modules/cms/front/themes/weixin/layouts/default.jsp" />
    

</decorators>

2、在页面文件中引用模版<meta name="decorator" content="cms_default_${site.theme}"/>

<head>
    <title>首页</title>
    <meta name="decorator" content="cms_default_${site.theme}"/>
    <meta name="description" content="JeeSite ${site.description}" />
    <meta name="keywords" content="JeeSite ${site.keywords}" />

</head>

其中content=“cms_default_${site.theme}”中的“cms_default_${site.theme}”对应“decorators.xml”配置文件中的“ name”属性值。

猜你喜欢

转载自blog.csdn.net/qsky001/article/details/79709994