工程目录

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. MySQL 语句中执行优先级——and比or高

    转: MySQL 语句中执行优先级——and比or高 2017年04月20日 13:33:03 十步行 阅读数:7381   版权声明:本文为博主原创文章,未经博主允许不得转载. https://bl ...

  2. Codeforces Round #423 (Div. 2, rated, based on VK Cup Finals) C 并查集

    C. String Reconstruction time limit per test 2 seconds memory limit per test 256 megabytes input sta ...

  3. 【题解】【LibreOJ Beta Round #5】游戏 LOJ 531 基环树 博弈论

    Prelude 题目链接:萌萌哒传送门♪(^∇^*) Subtask 1 & 2 这是什么鬼题面... 首先要看出,这就是一个基环树博弈. 具体题意:给出一个基环内向树,一个棋子初始在\(1\ ...

  4. 3.UiObejct API 详细介绍

    一.点击与长按 1.组件区域位置关系: Rect 对象代表一个矩形区域:[left,Top][ARight,Bottom](即左上角图标到右下角图标) 2.点击与长按相关API: 返回值 API 说明 ...

  5. Covariance 协方差分析

    sklearn实战-乳腺癌细胞数据挖掘 https://study.163.com/course/introduction.htm?courseId=1005269003&utm_campai ...

  6. centos7.2的yum安装mysql和修改初始密码

    一.centos7.2安装mysql CentOS 7之后的版本yum的默认源中使用MariaDB替代原先MySQL,因此安装方式较为以往有一些改变: 下载mysql的源 wget http://de ...

  7. swiper.js的使用

    点击api文档地址, (1)图片轮播banner <script src="js/jquery-2.1.4.min.js"></script> <sc ...

  8. NOIP2013 提高组 Day2

    期望得分:100+100+30+=230+ 实际得分:100+70+30=200 T2 觉得题目描述有歧义: 若存在2i却不存在2i+1,自己按不合法做的,实际是合法的 T3  bfs 难以估分 虽然 ...

  9. POJ 1389 Area of Simple Polygons 扫描线+线段树面积并

    ---恢复内容开始--- LINK 题意:同POJ1151 思路: /** @Date : 2017-07-19 13:24:45 * @FileName: POJ 1389 线段树+扫描线+面积并 ...

  10. 对WebView进行的一些设置

    webView.getSettings().setJavaScriptEnabled(true); //使用setting WebSettings webSettings = webView.getS ...