Sitemesh 3 的使用及配置
发布日期:2021-09-29 01:27:08 浏览次数:5 分类:技术文章

本文共 2540 字,大约阅读时间需要 8 分钟。

1 . Sitemesh 3 简介

Sitemesh 是一个网页布局和修饰的框架,基于 Servlet 中的 Filter,类似于 ASP.NET 中的‘母版页’技术。参考:,相关类似技术:。

官网: 。

2 . Sitemesh 3 下载

最新版本:3.0.0-SNAPSHOT

① GitHub 地址:

② maven:

1 
2
org.sitemesh
3
sitemesh
4
3.0.0
5

3 . 配置 Sitemesh 3 过滤器

在 web.xml 中添加 Sitemesh Filter: 

1 
2 3 ... 4 5
6
sitemesh
7
org.sitemesh.config.ConfigurableSiteMeshFilter
8
9
10
sitemesh
11
/*
12
13 14

4 . 准备两个页面:demo.html 和 decorator.html

① demo.html - “被装饰的页面”,实际要呈现的内容页。

1 2 3 4     内容页的标题5 6 7     内容页的body部分8 9 

② decorator.html - “装饰页面”,所谓的“母版页”。

1  2  3  4  5     <sitemesh:write property='title' /> - ltcms 6  7 
8 9 10
header
11

12 demo.html的title将被填充到这儿:13
14 demo.html的body将被填充到这儿:15
16

17
footer
18 19

5 . 添加 /WEB-INF/sitemesh3.xml

1 
2
3
4
5 6
7
8

6 . 运行效果

访问 demo.html 页面,实际效果如下:

7 . sitemesh3.xml 配置详解

1 
2
5
text/html
6
application/vnd.wap.xhtml+xml
7
application/xhtml+xml
8 ... 9 10
11
12 13
14
15
16 17
18
19
/articles/*
20
/decorators/article.html
21
/decorators/two-page-layout.html
22
/decorators/common.html
23
24 25
26
27
28 29
30
31
32
33
34 ...35 36

8 . 自定义 tag 规则

Sitemesh 3 默认只提供了 body,title,head 等 tag 类型,我们可以通过实现 TagRuleBundle 扩展自定义的 tag 规则:

1 public class MyTagRuleBundle implements TagRuleBundle { 2     @Override 3     public void install(State defaultState, ContentProperty contentProperty, 4             SiteMeshContext siteMeshContext) { 5         defaultState.addRule("myHeader", new ExportTagToContentRule(contentProperty.getChild("myHeader"), false)); 6          7     } 8      9     @Override10     public void cleanUp(State defaultState, ContentProperty contentProperty,11             SiteMeshContext siteMeshContext) {12     }13 }

最后在 sitemesh3.xml 中配置即可:

1 
2
3

 

转载地址:https://blog.csdn.net/happydecai/article/details/80350312 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!

上一篇:spring mvc:rest风格的资源url
下一篇:Spring事务的传播:PROPAGATION_REQUIRED

发表评论

最新留言

初次前来,多多关照!
[***.217.46.12]2024年03月28日 21时10分01秒