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

关于thymeleaf+layout布局的使用方式,spring boot 访问页面(静态页面及jsp页面)的更多相关文章

  1. Spring Boot项目跳转不到jsp页面是怎么回事

    SpringBoot访问不了JSP但却能进入后台 一直报错: 解决方法: 改成下面的

  2. 解决thymeleaf layout布局不生效

    今天使用thymeleaf layout布局时总是不生效,特此把解决问题的步骤和几个关键点记录下来备忘. 一.检查依赖 1.thymeleaf必备maven依赖: <dependency> ...

  3. Spring Boot 中的静态资源到底要放在哪里?

    当我们使用 SpringMVC 框架时,静态资源会被拦截,需要添加额外配置,之前老有小伙伴在微信上问松哥Spring Boot 中的静态资源加载问题:"松哥,我的HTML页面好像没有样式?& ...

  4. Spring Boot2 系列教程(十一)Spring Boot 中的静态资源配置

    当我们使用 SpringMVC 框架时,静态资源会被拦截,需要添加额外配置,之前老有小伙伴在微信上问松哥 Spring Boot 中的静态资源加载问题:"松哥,我的 HTML 页面好像没有样 ...

  5. Spring Boot实战:静态资源处理

    前两章我们分享了Spring boot对Restful 的支持,不过Restful的接口通常仅仅返回数据.而做web开发的时候,我们往往会有很多静态资源,如html.图片.css等.那如何向前端返回静 ...

  6. 使用spring boot访问mongodb数据库

    一. spring boot中传参的方法 1.自动化配置 spring Boot 对于开发人员最大的好处在于可以对 Spring 应用进行自动配置.Spring Boot 会根据应用中声明的第三方依赖 ...

  7. 【spring boot】7.静态资源和拦截器处理 以及继承WebMvcConfigurerAdapter类进行更多自定义配置

    开头是鸡蛋,后面全靠编!!! ========================================================  1.默认静态资源映射路径以及优先顺序 Spring B ...

  8. 【spring boot】5.spring boot 创建web项目并使用jsp作前台页面

    贼烦的是,使用spring boot 创建web项目,然后我再idea下创建的,but 仅仅启动spring boot的启动类,就算整个项目都是好着的,就算是能够进入controller中,也不能成功 ...

  9. Spring Boot - 访问外部接口最全总结

    Spring Boot - 访问外部接口 在Spring-Boot项目开发中,存在着本模块的代码需要访问外面模块接口,或外部url链接的需求, 比如调用外部的地图API或者天气API. Spring ...

随机推荐

  1. 茶道(tea)

    #include<iostream> #include<string> #include<stdio.h> #include<algorithm> #i ...

  2. Linux内核配置:Makefile目标

    在顶层Linux源码目录中输入命令make help,它会显示一长串从源码树中生成的目标列表.最常见的使用make的方式是不指定目标,在这种情况下,它会生成内核ELF文件vmlinux和针对所选架构的 ...

  3. Kettle命令行使用说明

    Kettle命令行使用说明 1.Pan——转换执行器 用来执行转换.参数与Kitchen类似,如下. 1- -version显示版本信息 2- -file=filename运行xml文件 3- -pa ...

  4. Jenkins 持续集成综合实战

    Jenkins 是一款流行的开源持续集成(Continuous Integration)工具,广泛用于项目开发,具有自动化构建.测试和部署等功能.本文以 CentOS7 环境为例,总结了 Jenkin ...

  5. js 实现继承的6种方式(逐渐优化)

    <!DOCTYPE html> <html lang="zh"> <head> <meta charset="UTF-8&quo ...

  6. SpringMVC学习笔记六:使用 hibernate-validator注解式数据校验

    对客户端传过来的参数,在使用前一般需要进行校验. SpringMVC框架内置了Validator验证接口,但是实现起来太麻烦.我们一般使用 hibernate-validator进行数据校验. 1:j ...

  7. 关于Android中50M+的文本入库处理细节

    好久没有写技术文章,明早4点还要爬起来赶飞机,感觉这个坑有必要记录一下,以慰藉一下自己脆弱的灵魂.周一和周二忙了2天的样子才解决这个问题,中间填了不少的坑,反正已经夜深了,慢慢地记录一点. 场景:项目 ...

  8. spiral-matrix-ii &i 生成顺时针序列

    I: Given a matrix of m x n elements (m rows, n columns), return all elements of the matrix in spiral ...

  9. jenkins里面使用批处理命令进行自动部署

    http://blog.csdn.net/hwhua1986/article/details/47974047

  10. 开源通用型渲染工具-SwiftShader--OpenGL的替代者

    SwiftShader 是一款用于在 CPU 上进行高性能图形渲染的软件库.Google 已经在很多产品中使用该内容库,包括 Chrome.Android 开发工具和云服务.Swiftshader 从 ...