工程目录

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. python函数的输入参数

    http://note.youdao.com/noteshare?id=c2a0a39ee3cae09a62dcbc9f96d04b56

  2. apk文件签名绕过

    声明: 1.本文转载自:http://www.2cto.com/Article/201311/256406.html,为了留作日后参考上传博客 2.如有转载请复试上面连接,尊重原创 apk文件签名绕过 ...

  3. Splay 区间操作

    据大佬说,\(Splay\)是序列操作之王.\(Splay\)是一种平衡树,通过伸展(\(Splay\)),在不改变中序遍历的前提下变换根的位置,从而快速的进行序列操作 \(Splay\)最常见的序列 ...

  4. python---websocket的使用

    一:简介 推文:WebSocket 是什么原理?为什么可以实现持久连接? 推文:WebSocket:5分钟从入门到精通(很好) WebSocket协议是基于TCP的一种新的协议.WebSocket最初 ...

  5. Vue.js基础 笔记

    Vue.js的声明: < script src = “https://unpkg.com/vue” ></ script > el:值可以是CSS选择符.HTML元素.或者是返 ...

  6. Idea工具常用技巧总结

    转自:https://www.jianshu.com/p/131c2deb3ecf Idea常用技巧总结 1.无处不在的跳转 注:这里的快捷键是自己定义的,并非大家的都一样,可以通过findActio ...

  7. 软件测试(三)—— 参数化测试用例(Nextday.java)

    import static org.junit.Assert.*; import java.lang.reflect.Array; import java.util.Arrays; import ja ...

  8. linux系统df和du命令的区别

    发现一台用户的电脑,df检查出来的/磁盘空间占用了16G,比用du查看得到的磁盘空间大的多,du查看/下所有程序目录加起来还不到5G.这是什么原因呢? 即便是有隐藏文件,查了也很小啊.   因为df和 ...

  9. CSS预处理器们

    CSS预处理器有很多,最早的是2006年的Less,到后来2010年的SASS,还有现在也很出名的Stylus.不过要使用它们都要使用一些工具,比如Less的话要使用Grunt或者Gulp或者Node ...

  10. Disruptor的使用

    ..................2015年的第一天................... 本文代码托管在 https://github.com/hupengcool/disruptor-start ...