工程目录

pom.xml

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>springboot-demo</artifactId>
<groupId>cn.xiaojf</groupId>
<version>1.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion> <artifactId>springboot-sitemesh3</artifactId> <dependencies> <dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency> <dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-freemarker</artifactId>
</dependency> <dependency>
<groupId>org.sitemesh</groupId>
<artifactId>sitemesh</artifactId>
<version>3.0.1</version>
</dependency>
</dependencies> </project>

自定义过滤器,配置拦截规则,

Meshsite3Filter.java
package cn.xiaojf.springboot.sitemesh3.filter;

import cn.xiaojf.springboot.sitemesh3.tagrule.MyTagRuleBundle;
import org.sitemesh.builder.SiteMeshFilterBuilder;
import org.sitemesh.config.ConfigurableSiteMeshFilter; /**
* sitemesh 自定义配置
* @author xiaojf 2017/12/21 16:12
*/
public class Meshsite3Filter extends ConfigurableSiteMeshFilter {
@Override
protected void applyCustomConfiguration(SiteMeshFilterBuilder builder) {
builder.addDecoratorPath("/*", "/decorator/default")//拦截规则,/decorator/default 会被转发
.addExcludedPath("/static/**") //白名单
.addTagRuleBundle(new MyTagRuleBundle())//自定义标签
;
}
}

加入web过滤器

WebConfigure.java
package cn.xiaojf.springboot.sitemesh3.configure;

import cn.xiaojf.springboot.sitemesh3.filter.Meshsite3Filter;
import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter; @Configuration
public class WebConfigure extends WebMvcConfigurerAdapter {
@Bean
public FilterRegistrationBean siteMeshFilter() {
FilterRegistrationBean fitler = new FilterRegistrationBean();
Meshsite3Filter siteMeshFilter = new Meshsite3Filter();
fitler.setFilter(siteMeshFilter);
return fitler;
}
}

编写web controller

DecoratorController.java

package cn.xiaojf.springboot.sitemesh3.web.controller;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping; @Controller
@RequestMapping("/decorator")
public class DecoratorController {
@RequestMapping("default")
public String defaultDecorator() {
return "/decorator/default";
}
}

MeshsiteController.java

package cn.xiaojf.springboot.sitemesh3.web.controller;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping; @Controller
@RequestMapping("/")
public class MeshsiteController {
@RequestMapping("home")
public String home() {
return "home";
} }

编写母版文件

default.html

<html>
<head>
<title>
<sitemesh:write property='title'/>
</title>
<sitemesh:write property='head'/>
</head>
<body> title的内容 <sitemesh:write property='title'/><br/> body的内容 <sitemesh:write property='body'/><br/> myTag的内容 <sitemesh:write property='myTag'/><br/> </body>
</html>

编写被修饰文件 home.html

<html>
<head>
<title>title</title>
</head>
<body> <myTag>
custom mytag
</myTag> hello meshsite
</body>
</html>

查看效果

http://localhost:8010/home

源码地址

https://gitee.com/xiaojf/springboot-demo/tree/master/springboot-sitemesh3

springboot 集合 meshsite3的更多相关文章

  1. spring-boot 集合mybatis 的分页查询

    spring-boot 集合mybatis 的github分页查询 一.依赖包 <!-- mysql 数据库驱动. --> <dependency> <groupId&g ...

  2. springboot集合jpa使用

    现目前java中用较多的数据库操作框架主要有:ibatis,mybatis,hibernate:今天分享的是jpa框架,在springboot框架中能够很快并方便的使用它,就我个人而言觉得如果是做业务 ...

  3. springboot集合pagehelper分页不生效的原因

    也可以

  4. SpringBoot集合Linux的FastDFS与Nginx上传图片测试错误com.github.tobato.fastdfs.exception.FdfsConnectException: 无法获取服务端连接资源:can't create connection to/192.168.1.104:22122

    报错 com.github.tobato.fastdfs.exception.FdfsConnectException: 无法获取服务端连接资源:can't create connection to/ ...

  5. SpringBoot系列教程web篇之Freemaker环境搭建

    现在的开发现状比较流行前后端分离,使用springboot搭建一个提供rest接口的后端服务特别简单,引入spring-boot-starter-web依赖即可.那么在不分离的场景下,比如要开发一个后 ...

  6. pom大全

    springboot集合 父模块 <parent> <groupId>org.springframework.boot</groupId> <artifact ...

  7. swagger ui demo

    前言 前几天一个朋友公司在用Springboot集合swagger时候总是从浏览器看不了接口,我两找了问题,但是他还是没有找到,于是我就自己从http://start.spring.io/上下载了一个 ...

  8. springboot~mongo内嵌集合的操作

    对于mongodb的内嵌对象的各种操作大叔在.net平台时已经说过,同时大叔也自己封装过mongo的仓储,使用也都很方便,而在java springboot框架里当然也有对应的方法,下面主要说一下,希 ...

  9. 【springboot】【redis】springboot结合redis,操作List集合实现时间轴功能

    springboot结合redis,操作List集合实现时间轴功能

随机推荐

  1. linux 进程信号集合 sigset_t

    sigset_t 号集及信号集操作函数:信号集被定义为一种数据类型: typedef struct { unsigned long sig[_NSIG_WORDS]: } sigset_t 信号集用来 ...

  2. Codeforces Round #338 (Div. 2) D 数学

    D. Multipliers time limit per test 2 seconds memory limit per test 256 megabytes input standard inpu ...

  3. sloop公共函数之添加信号,定时器及socket

    1:添加信号 1.1 原型:sloop_handle sloop_register_signal(int sig, sloop_signal_handler handler, void * param ...

  4. 金牌架构师:我们是这样设计APP数据统计产品的

    前言:近期,智能大数据服务商“个推”推出了应用统计产品“个数”,今天我们就和大家来谈一谈个数实时统计与AI数据智能平台整合架构设计. 很多人可能好奇,拥有数百亿SDK的个推,专注消息推送服务多年,现在 ...

  5. input模拟

    <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title> ...

  6. java类的静态属性值获取

    获取某个类实例的静态属性: public class ErrorCode { private String code; private String message; private ErrorCod ...

  7. Arrays.asList方法遇到的问题

    在使用Arrays.asList(T...a)方法时,遇到了 java.lang.UnsupportedOperationException  异常. 后来发现,该方法返回的类型是Arrays$Arr ...

  8. STL在算法比赛中简单应用

    STL基础 和 简单的贪心问题 STL(Standard Template Library) 即 标准模板库. 它包含了诸多在计算机科学领域里所常用的基本数据结构和算法.这些数据结构可以与标准算法一起 ...

  9. python_继承.ziw

    2017年1月2日, 星期一 python_继承   null

  10. 应用于网站导航中的 12 个 jQuery 插件

    当考虑到网页设计时,导航被认为是使网页以用户友好方式展现的一个重要部分.在现代的交互网站中,导航起着至关重要的作用,如果没有正确地处理会影响你网站的访问.适当的导航工具能够帮助用户在网站的不同页面内容 ...