SpringBoot中如何实现公共页面抽取技巧详解?

2026-05-25 21:442阅读0评论SEO教程
  • 内容介绍
  • 文章标签
  • 相关推荐

本文共计838个文字,预计阅读时间需要4分钟。

SpringBoot中如何实现公共页面抽取技巧详解?

目录 + 1. 需求描述 + 2. 使用Thymeleaf抽取公共页面方法 + 3. insert、replace与include抽取公共页面的区别 + 1. 需求描述 + 我们有一个页面,包括左右导航和上方导航,切换内容时,导航栏保持不变。

目录
  • 1. 需求描述
  • 2. 使用 thymeleaf 抽取公共页面方法
  • 3. insert与replace及include抽取公共页面的区别

1. 需求描述

我们有这样一个页面,其具有左侧导航和上侧导航,在切换不同内容过程中,左侧导航和上册导航不变,也就是说我们想将左侧导航和上侧导航这个公共部分抽取出来。

注意:使用 thymeleft 必须引入 <html lang="en" xmlns:th="www.thymeleaf.org">

2. 使用 thymeleaf 抽取公共页面方法

利用 thymeleaf 的 insert、replace 及 include 方法。

首先创建一公共页面 html,叫做 common.html,把公共的内容放进去。并通过 id="leftmenu"th:fragment="headermenu" 标注需要抽取的内容。

阅读全文

本文共计838个文字,预计阅读时间需要4分钟。

SpringBoot中如何实现公共页面抽取技巧详解?

目录 + 1. 需求描述 + 2. 使用Thymeleaf抽取公共页面方法 + 3. insert、replace与include抽取公共页面的区别 + 1. 需求描述 + 我们有一个页面,包括左右导航和上方导航,切换内容时,导航栏保持不变。

目录
  • 1. 需求描述
  • 2. 使用 thymeleaf 抽取公共页面方法
  • 3. insert与replace及include抽取公共页面的区别

1. 需求描述

我们有这样一个页面,其具有左侧导航和上侧导航,在切换不同内容过程中,左侧导航和上册导航不变,也就是说我们想将左侧导航和上侧导航这个公共部分抽取出来。

注意:使用 thymeleft 必须引入 <html lang="en" xmlns:th="www.thymeleaf.org">

2. 使用 thymeleaf 抽取公共页面方法

利用 thymeleaf 的 insert、replace 及 include 方法。

首先创建一公共页面 html,叫做 common.html,把公共的内容放进去。并通过 id="leftmenu"th:fragment="headermenu" 标注需要抽取的内容。

阅读全文