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. vsphere脚本等

  2. POSTGRESQL 创建表结构、修改字段、导入导出数据库(支持CSV)

    这两个月经常使用postgresql,总结一些经常使用的语句: --创建表 CREATE TABLE customers ( customerid SERIAL primary key , compa ...

  3. SpringMVC的页面几种返回方式

    package com.boventech.learning.controller; import java.util.HashMap; import java.util.Map; import or ...

  4. vue中的ajax - axios

    vue中的ajax - axios axios - 简书 使用 axios 实现 ajax 方案 VUE 更好的 ajax 上传处理 axios.js vue.js 自2.0版本已经不对 vue-re ...

  5. CentOS下Crontab安装使用详细说明(转)

    来自:http://www.centoscn.com/CentOS/help/2014/1220/4346.html crontab命令常见于Unix和Linux的操作系统之中,用于设置周期性被执行的 ...

  6. SSH使用Slf4j

    1. Slf4j的使用 在上一篇随笔:SSH使用Log4j的基础上配置. (1)导入两个文件:slf4j-api-1.5.8.jar和slf4j-log4j12-1.5.8.jar. (2)在需要日志 ...

  7. intellij 创建测试

    之后再test目录下面创建java的文件夹,悲催的发现不能创建.想了好久,之后找到再本机的目录,手动创建java文件夹,然后点击test文件夹 ,并且点击下面的Tests文件夹 设置完test-> ...

  8. 使用 git post-receive 钩子部署服务端代码

    在 git 中提交服务器源码的时候,如果能够直接更新到测试服务器,并且重启服务使其生效,会节省懒惰的程序员们大量的时间. git 的 Server-side hook (服务端钩子/挂钩)可以用来做件 ...

  9. Changing the Language Used in ODI Studio

    odi.conf中加入区域和语言设置 修改 "$ODI_HOME\odi\studio\bin\odi.conf"    ( D:\Oracle\Middleware\Oracle ...

  10. django生成文件txt、pdf(在生成 PDF 文件之前,需要安装 ReportLab 库)

    from django.http import HttpResponse def download_file(request): # Text file #response = HttpRespons ...