1.9 Spring Boot 2.x 集成 Thymeleaf

1.9.1 在pom中引入依赖

        <dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
<!--用来非严格的Html格式-->
<!-- https://mvnrepository.com/artifact/net.sourceforge.nekohtml/nekohtml -->
<dependency>
<groupId>net.sourceforge.nekohtml</groupId>
<artifactId>nekohtml</artifactId>
<version>${nekohtml.version}</version>
</dependency>

1.9.2 yml文件中配置

spring:
thymeleaf:
cache: false # 开发时关闭缓存,不然没法看到实时页面
mode: LEGACYHTML5 # 用非严格的 HTML
encoding: UTF-8
servlet:
content-type: text/html

1.9.3 创建HelloController


package com.hw.springbootthymeleaf.web; import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable; /**
* @Description TODO
* @Author hw
* @Date 2018/11/21 18:07
* @Version 1.0
*/
@Controller
public class HelloController { @GetMapping("index/{data}")
public String index(Model model, @PathVariable String data) {
model.addAttribute("key", data);
return "index";
}
}

1.9.4 添加模板文件

  • thymeleaf模板文件默认在 resource/templates 目录下
  • 记得每个文件都要添加 xmlns:th="http://www.thymeleaf.org" 声明才能使用thymeleaf语法
<!DOCTYPE html SYSTEM "http://www.thymeleaf.org/dtd/xhtml1-strict-thymeleaf-spring4-4.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:th="http://www.thymeleaf.org">
<head>
<meta charset="UTF-8">
<title>Hello Thymeleaf</title>
</head>
<body>
<div>
<span>访问 Model:</span><span th:text="${key}"></span>
</div>
</body>
</html>

9、Spring Boot 2.x 集成 Thymeleaf的更多相关文章

  1. Spring Boot学习记录(二)--thymeleaf模板 - CSDN博客

    ==他的博客应该不错,没有细看 Spring Boot学习记录(二)--thymeleaf模板 - CSDN博客 http://blog.csdn.net/u012706811/article/det ...

  2. spring boot / cloud (三) 集成springfox-swagger2构建在线API文档

    spring boot / cloud (三) 集成springfox-swagger2构建在线API文档 前言 不能同步更新API文档会有什么问题? 理想情况下,为所开发的服务编写接口文档,能提高与 ...

  3. Spring Boot HikariCP 一 ——集成多数据源

    其实这里介绍的东西主要是参考的另外一篇文章,数据库读写分离的. 参考文章就把链接贴出来,里面有那位的代码,简单明了https://gitee.com/comven/dynamic-datasource ...

  4. Spring Boot系列——如何集成Log4j2

    上篇<Spring Boot系列--日志配置>介绍了Spring Boot如何进行日志配置,日志系统用的是Spring Boot默认的LogBack. 事实上,除了使用默认的LogBack ...

  5. Spring Boot 2.0 整合Thymeleaf 模板引擎

    本节将和大家一起实战Spring Boot 2.0 和thymeleaf 模板引擎 1. 创建项目 2. 使用Spring Initlizr 快速创建Spring Boot 应用程序 3. 填写项目配 ...

  6. 【ELK】4.spring boot 2.X集成ES spring-data-ES 进行CRUD操作 完整版+kibana管理ES的index操作

    spring boot 2.X集成ES 进行CRUD操作  完整版 内容包括: ============================================================ ...

  7. Spring Boot + MyBatis + Druid + Redis + Thymeleaf 整合小结

    Spring Boot + MyBatis + Druid + Redis + Thymeleaf 整合小结 这两天闲着没事想利用**Spring Boot**加上阿里的开源数据连接池**Druid* ...

  8. 15、Spring Boot 2.x 集成 Swagger UI

    1.15.Spring Boot 2.x 集成 Swagger UI 完整源码: Spring-Boot-Demos 1.15.1 pom文件添加swagger包 <swagger2.versi ...

  9. 14、Spring Boot 2.x 集成 Druid 数据源

    14.Spring Boot 2.x 集成 Druid 数据源 完整源码: Spring-Boot-Demos

随机推荐

  1. WebSocket 中的Netty

    测试Channelhandler   EmbeddedChannel提供了下面一些方法: writeInbound(Object...),写一个消息到入站通道 writeOutbound(Object ...

  2. 关于 磁盘 I/O 的工作机制那些事

    总有一些你我看不见的东西,存在与你我周围 <深入分析 javaW 技术内幕> 读书感悟 作者 :淮左白衣 写于2018年4月11日19:35:06 写在前面的话 字节与字符的转换桥梁 用户 ...

  3. 1266: gcd和lcm(Java)

    WUSTOJ 1266: gcd和lcm 参考 1naive1的博客 Description   已知a,b的最大公约数为x,也即gcd(a,b)=x; a,b的最小公倍数为y,也即lcm(a,b)= ...

  4. vim编辑器中的替换(转)

    转1:https://www.cnblogs.com/david-wei0810/p/6385988.html 转2:https://blog.csdn.net/doubleface999/artic ...

  5. (七)shiro之编码/加密

    一.编码/解码 使用Base64编码/解码操作 public class TestMain { public static void main(String[] args) { SecurityMan ...

  6. VBA Excel宏(二)

    在本章中,我们来学习如何逐步编写一个简单的宏. 第1步 - 首先,在Excel 2016中启用“开发者”菜单.要完成这个设置,请点击左上角菜单:文件 -> 选项.如下图所示 - 第2步 - 点击 ...

  7. JavaScript引入

    三种引入方式 js标签引入的三种方式 1.行间式 写在标签的事件属性中 <div onclick="alert('hello')"></div>(点击出弹窗 ...

  8. ES6箭头函数及this指向

    箭头函数(=>):函数简写 无参数:() => {} 单个参数:x => {} 多个参数:(x, y) => {} 解构参数:({x, y}) => {} 嵌套使用:部署 ...

  9. K2 BPM_携手捷普:让流程立于云端,臻于至上_全球领先的工作流引擎

    在工业4.0地催化下,新一代信息技术与高科制造业深度融合,正在引发影响深远的产业变革,形成了新的生产方式.产业形态.商业模式和经济增长点. 捷普作为世界上最大型的电子制造服务公司之一,正站在新的历史发 ...

  10. ASE19团队项目 beta阶段 model组 scrum2 记录

    本次会议于12月3日,19时整在微软北京西二号楼sky garden召开,持续10分钟. 与会人员:Jiyan He, Kun Yan, Lei Chai, Linfeng Qi, Xueqing W ...