1. 首先建立相同部分的html,这里我命名为layout.html,放在了`templates/layout'文件夹下,这个路径以后是会用到的,以下是我的layout的代码,比较粗糙.
    但是应该会更好的帮助理解.
    要提到几个重要的部分
<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org"
xmlns:layout="http://www.ultraq.net.nz/web/thymeleaf/layout">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<style>
* {font-family: Microsoft YaHei, Tahoma, Helvetica, Arial, sans-serif;}
.header {background-color: #f5f5f5;padding: 20px;}
.header a {padding: 0 20px;}
.container {padding: 20px;margin:20px auto;}
.footer {height: 40px;background-color: #f5f5f5;border-top: 1px solid #ddd;padding: 20px;}
</style>
</head>
<body>
<header class="header">
<div>
测试接口Demo
</div>
</header>
<div class="container" layout:fragment="content"></div>
<footer class="footer">
<div>
<p style="float: left">&copy;TestS</p>
</div>
</footer> </body>
</html>
  1. 然后建立新的html,这里我建立的是一个简单的添加用户的界面add.html,代码如下
    要提到的几个重要的部分
  • <html lang="zh-CN"
    xmlns="http://www.w3.org/1999/xhtml"
    xmlns:th="http://www.thymeleaf.org"
    xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout"
    layout:decorator="demolayout/layout1">

    前边我们提到的路径,这个就是你layout.html文件的位置.

  • <div layout:fragment="content" > 设置div content 然后就可以将你需要更改的内容写在这个位置
    1. 之前在写到这的时候就直接跑程序了 ,发现不好用,但是感觉写的没有问题 ,最后找到了问题所在,在meaven中没有配置thmeleaf,
      所以在meaven中添加如下代码
        <dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency> <dependency>
<groupId>nz.net.ultraq.thymeleaf</groupId>
<artifactId>thymeleaf-layout-dialect</artifactId>
</dependency>

参考:https://www.jianshu.com/p/3b5ebc545a99

最新文章

  1. JS重载
  2. [原] Intellij IDEA开发Android,祝还在使用eclipse的早日脱离苦海
  3. [WF] Quickstart Sample
  4. MyEclipse8.5 以debug模式启动tomcat6.0服务器 报错cannot connect to vm。
  5. EntityFramework:支持同一事务提交的批量删除数据实现思路
  6. org.apache.hadoop.filecache-*
  7. 1、发布C++实现的TCP网络框架Khala
  8. 多线程笔记--原子操作Interlocked系列函数
  9. 浅谈C/C++引用和指针的联系和区别
  10. 关于Webdriver自动化测试时,页面数据与数据库id不一致的处理方式,需要使用鼠标事件
  11. from nltk.book import * 出错的解决方法
  12. [Swift]LeetCode676. 实现一个魔法字典 | Implement Magic Dictionary
  13. AtCoDeerくんと選挙速報 / AtCoDeer and Election Report AtCoder - 2140 (按比例扩大)
  14. Python AES_ECB_PKCS5加密代码
  15. freeswitch 显示主叫名称和主叫号码
  16. Scrapy实战篇(一)之爬取链家网成交房源数据(上)
  17. 使用vscode编译sass
  18. [C#.net]Connection Timeout和Command Timeout
  19. HDU 5889 Barricade(最短路+最小割)
  20. CAN总线的显性电平为什么能覆盖隐性电平?

热门文章

  1. VMware Infrastructure 3 in a Cisco Network Environment
  2. 使用electron+Js开发夸平台(Linux、Win、Mac)的桌面应用程序
  3. Mina.Net实现的UDP协议消息收发Demo
  4. 整合Tomcat和Nginx实现动静态负载均衡
  5. MoveIt运动规划-1
  6. 实现Excel单元格中的下拉选项
  7. docker overlay存储驱动介绍(传送门)
  8. LVM逻辑卷管理测试——逻辑卷扩展、收缩、快照及删除
  9. 从零開始学android&amp;lt;AnalogClock与DigitalClock时钟组件.三十一.&amp;gt;
  10. Xcode7 运行iOS10以上系统(10.1、10.2、10.3)解决Could not find Developer Disk Image