spring boot integrated sitemesh
Sitemesh Introduction
Sitemesh is a framework based on Web page layout, decoration and integration with existing Web applications. It is a decorator. It can help us create consistent page layout and appearance in projects with a large number of page projects, such as consistent navigation bars, consistent banners, consistent copyrights, etc.
SiteMesh is based on Servlet filter. It intercepts the response and decorates it before delivering it to the client.
spring boot integrates sitemesh
The work to be done for integration is very simple:
1. Introduce the sitemesh.jar package
2 , add a configuration class and filter class
3, add a decorator page
2.1, introduce the sitemesh.jar package
Introduce in the maven pom file:
<dependency> <groupId>org.sitemesh</groupId> <artifactId>sitemesh</artifactId> <version>3.0.1</version> </dependency>
Configuration class and filter class
The configuration class is as follows:
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; //生效配置,使之就像传统项目里sping的xml配置文件一样 @Configuration public class WebConfig extends WebMvcConfigurerAdapter{ //注册成bean,就像传统项目spring配置文件中的<bean>标签 @Bean public FilterRegistrationBean siteMeshFilter(){ FilterRegistrationBean fitler = new FilterRegistrationBean(); //实例化一个过滤器类 WebSiteMeshFilter siteMeshFilter = new WebSiteMeshFilter(); fitler.setFilter(siteMeshFilter); return fitler; } } 过滤器类如下: import org.sitemesh.builder.SiteMeshFilterBuilder; import org.sitemesh.config.ConfigurableSiteMeshFilter; public class WebSiteMeshFilter extends ConfigurableSiteMeshFilter{ @Override protected void applyCustomConfiguration(SiteMeshFilterBuilder builder) { //除了/admin/index和/admin/login页面外,其他所有/admin/下的页面都被/admin/index页面所装饰 builder.addDecoratorPath("/admin/*", "/admin/index") .addExcludedPath("/admin/index") .addExcludedPath("/admin/login"); } }
Decorator page
The decorator page is the template page, and the pages defined in the filter rules will be decorated by this page.
<!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml" xmlns:th="http://www.thymeleaf.org" xmlns:sec="http://www.thymeleaf.org/thymeleaf-extras-springsecurity3"> <head> <title>装饰器页面</title> </head> <body> ... <div id="content"> <sitemesh:write property='body' /> </div> </body> </html>
With the above decorator page, when we visit the decorated page such as /admin/test, the displayed content is the content within the body element of the decorated page on the decorator page,
<!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml" xmlns:th="http://www.thymeleaf.org" xmlns:sec="http://www.thymeleaf.org/thymeleaf-extras-springsecurity3"> <head> <title>test页面</title> </head> <body> <h1>我是test</h1> </body> </html>
The final page is:
<!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml" xmlns:th="http://www.thymeleaf.org" xmlns:sec="http://www.thymeleaf.org/thymeleaf-extras-springsecurity3"> <head> <title>装饰器页面</title> </head> <body> ... <div id="content"> <h1>我是test</h1> </div> </body> </html>
The above is the detailed content of spring boot integrated sitemesh. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



In actual projects, we try to avoid distributed transactions. However, sometimes it is really necessary to do some service splitting, which will lead to distributed transaction problems. At the same time, distributed transactions are also asked in the market during interviews. You can practice with this case, and you can talk about 123 in the interview.

With the development of globalization, more and more websites and applications need to provide multi-language support and internationalization functions. For developers, implementing these functions is not an easy task because it requires consideration of many aspects, such as language translation, date, time and currency formats, etc. However, using the SpringBoot framework, we can easily implement multi-language support and international applications. First, let us understand the LocaleResolver interface provided by SpringBoot. Loc

With the rise of digital currencies such as Bitcoin, blockchain technology has gradually become a hot topic. Smart contracts can be regarded as an important part of blockchain technology. SpringBoot, as a popular Java back-end development framework, can also be used to build blockchain applications and smart contracts. This article will introduce how to use SpringBoot to build applications and smart contracts based on blockchain technology. 1. SpringBoot and blockchain First, we need to understand some basic concepts related to blockchain. Blockchain

In the development process of Java web applications, ORM (Object-RelationalMapping) mapping technology is used to map relational data in the database to Java objects, making it convenient for developers to access and operate data. SpringBoot, as one of the most popular Java web development frameworks, has provided a way to integrate MyBatis, and MyBatisPlus is an ORM framework extended on the basis of MyBatis.

With the development of the Internet, big data analysis and real-time information processing have become an important need for enterprises. In order to meet such needs, traditional relational databases no longer meet the needs of business and technology development. Instead, using NoSQL databases has become an important option. In this article, we will discuss the use of SpringBoot integrated with NoSQL databases to enable the development and deployment of modern applications. What is a NoSQL database? NoSQL is notonlySQL

With the advent of the big data era, more and more companies are beginning to understand and recognize the value of big data and apply it to business. The problem that comes with it is how to handle this large flow of data. In this case, big data processing applications have become something that every enterprise must consider. For developers, how to use SpringBoot to build an efficient big data processing application is also a very important issue. SpringBoot is a very popular Java framework that allows

With the continuous development and popularization of the Internet, the demand for data processing and storage is also increasing. How to process and store data efficiently and reliably has become a hot topic among industry and researchers. The distributed data caching and storage system based on SpringBoot is a solution that has attracted much attention in recent years. What is a distributed data caching and storage system? Distributed data caching and storage system refers to the distributed storage of data through multiple nodes (servers), which improves the security and reliability of data, and can also improve data processing.

As modern businesses rely more and more on a variety of disparate applications and systems, enterprise integration becomes even more important. Enterprise Service Bus (ESB) is an integration architecture model that connects different systems and applications together to provide common data exchange and message routing services to achieve enterprise-level application integration. Using SpringBoot and ApacheServiceMix, we can easily build an ESB system. This article will introduce how to implement it. SpringBoot and A
