springboot 集合 meshsite3
工程目录
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的更多相关文章
- spring-boot 集合mybatis 的分页查询
spring-boot 集合mybatis 的github分页查询 一.依赖包 <!-- mysql 数据库驱动. --> <dependency> <groupId&g ...
- springboot集合jpa使用
现目前java中用较多的数据库操作框架主要有:ibatis,mybatis,hibernate:今天分享的是jpa框架,在springboot框架中能够很快并方便的使用它,就我个人而言觉得如果是做业务 ...
- springboot集合pagehelper分页不生效的原因
也可以
- 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/ ...
- SpringBoot系列教程web篇之Freemaker环境搭建
现在的开发现状比较流行前后端分离,使用springboot搭建一个提供rest接口的后端服务特别简单,引入spring-boot-starter-web依赖即可.那么在不分离的场景下,比如要开发一个后 ...
- pom大全
springboot集合 父模块 <parent> <groupId>org.springframework.boot</groupId> <artifact ...
- swagger ui demo
前言 前几天一个朋友公司在用Springboot集合swagger时候总是从浏览器看不了接口,我两找了问题,但是他还是没有找到,于是我就自己从http://start.spring.io/上下载了一个 ...
- springboot~mongo内嵌集合的操作
对于mongodb的内嵌对象的各种操作大叔在.net平台时已经说过,同时大叔也自己封装过mongo的仓储,使用也都很方便,而在java springboot框架里当然也有对应的方法,下面主要说一下,希 ...
- 【springboot】【redis】springboot结合redis,操作List集合实现时间轴功能
springboot结合redis,操作List集合实现时间轴功能
随机推荐
- 【莫队】【P3834】 【模板】可持久化线段树 1(主席树)
大家好,我是个毒瘤,我非常喜欢暴力数据结构,于是我就用莫队+分块过了这个题 Solution 发现这个题静态查询资瓷离线,于是考虑莫队. 在这里简单介绍一下莫队: 将所有询问离线后,对原序列分块.按照 ...
- 《剑指offer》— JavaScript(5)用两个栈实现队列
用两个栈实现队列 题目描述 用两个栈来实现一个队列,完成队列的Push和Pop操作. 队列中的元素为int类型. 实现代码 function Stack(){ var item = []; this. ...
- opencv 获取摄像头图像
http://www.cnblogs.com/epirus/archive/2012/06/04/2535190.html #include "stdafx.h" #include ...
- 使用gulp进行css、js压缩
var gulp = require('gulp'); var cleanCSS = require('gulp-clean-css'); var concatCss = require('gulp- ...
- 防止xss攻击的核心代码
public class XssFilter implements Filter { @Override public void destroy() { } /** * 过滤器用来过滤的方法 */ @ ...
- bzoj 3834 [Poi2014]Solar Panels 数论分块
3834: [Poi2014]Solar Panels Time Limit: 20 Sec Memory Limit: 128 MBSubmit: 367 Solved: 285[Submit] ...
- JAVA Remote Object
RMI(Remote Method Invocation)远程方法调用是一种计算机之间利用远程对象相互调用实现双方通讯的一种通讯机制.使用这种机制,某一台计算机上的对象可以调用另一台计算机上的对象来获 ...
- OpenCV---图像梯度
图像梯度 推文:[OpenCV入门教程之十二]OpenCV边缘检测:Canny算子,Sobel算子,Laplace算子,Scharr滤波器合辑 图像梯度可以把图像看成二维离散函数,图像梯度其实就是这个 ...
- Android图片压缩工具MCompressor
这是一个简单的图片压缩工具(MCompressor),可自定义压缩的格式和质量,以及压缩后存储的文件路径,可决定对多大的文件进行压缩. 使用方法 build.gradle文件 Step 1. Add ...
- CCD与CMOS的区别
我们在购买相机或是摄像机时,都会看到使用CMOS镜头或是CCD镜头,那么CCD与CMOS是什么意思呢,CCD与CMOS的区别是什么?首先,让我们了解CCD与CMOS的意思. CCDCCD使用一种高感光 ...