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集合实现时间轴功能
随机推荐
- 用一次FastDFS
FastDFS c编写的分布式文件系统,用于搭建文件服务器集群提供文件的上传.下载 特点 冗余备份 负载均衡 线性扩容 高性能.高可用 FastDFS架构 Tracker server 负载均衡和调度 ...
- oracle 数据库记录
/*----------------------------------------------------------------------------*/ 问题1[--------] Selec ...
- js 根据url 下载图片
downloadIamge(imgsrc, name) {//下载图片地址和图片名 let image = new Image(); // 解决跨域 Canvas 污染问题 image.setAttr ...
- 为Azure Web Site 添加ADFS验证支持之二 在代码里使用ADFS
下面我们来创建一个MVC 5.0的ASP.Net程序,并且将它部署到Azure Web Site上 通过Visual Studio 2015创建Web Project 在选择ASP.net模板的地方, ...
- [DeeplearningAI笔记]序列模型1.5-1.6不同类型的循环神经网络/语言模型与序列生成
5.1循环序列模型 觉得有用的话,欢迎一起讨论相互学习~Follow Me 1.5不同类型的循环神经网络 上节中介绍的是 具有相同长度输入序列和输出序列的循环神经网络,但是对于很多应用\(T_{x}和 ...
- vue-router路由原理
Vue-router路由原理 目前实现路由的方式有两中,vue通过参数mode来设置,默认是hash模式. 利用URL中的hash(‘#’)来实现 利用History interface在HTML5中 ...
- (转)使用Excel批量给数据添加单引号和逗号
在使用PLSQL连接oracle数据库处理数据的过程中,常用的操作是通过ID查询出数据,ID需要附上单引号,如果查询的ID为一条或者几条,我们手动添加即可,但是如果是几百条.几千条的话,就需要使用一些 ...
- 重构改善既有代码设计--重构手法10:Move Method (搬移函数)
你的程序中,有个函数与其所驻类之外的另一个类进行更多的交流:调用后者,或被后者调用.在该函数最常用引用的类中建立一个有着类似行为的新函数.将旧函数编程一个单纯的委托函数,或是将旧函数完全移除. 动机: ...
- Java实现链式存储的二叉树
二叉树的定义: 二叉树(BinaryTree)是n(n≥0)个结点的有限集,它或者是空集(n=0),或者由一个根结点及两棵互不相交的.分别称作这个根的左子树和右子树的二叉树组成. 二叉树的遍历方式主要 ...
- form表单设置input文本属性只读,不可更改
记住一条好用的,设置readonly属性为true <input readonly=''true"> 更多方法,转载: http://www.jb51.net/web/6 ...