9、Spring Boot 2.x 集成 Thymeleaf
1.9 Spring Boot 2.x 集成 Thymeleaf
- 完整源码: Spring-Boot-Demos
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的更多相关文章
- Spring Boot学习记录(二)--thymeleaf模板 - CSDN博客
==他的博客应该不错,没有细看 Spring Boot学习记录(二)--thymeleaf模板 - CSDN博客 http://blog.csdn.net/u012706811/article/det ...
- spring boot / cloud (三) 集成springfox-swagger2构建在线API文档
spring boot / cloud (三) 集成springfox-swagger2构建在线API文档 前言 不能同步更新API文档会有什么问题? 理想情况下,为所开发的服务编写接口文档,能提高与 ...
- Spring Boot HikariCP 一 ——集成多数据源
其实这里介绍的东西主要是参考的另外一篇文章,数据库读写分离的. 参考文章就把链接贴出来,里面有那位的代码,简单明了https://gitee.com/comven/dynamic-datasource ...
- Spring Boot系列——如何集成Log4j2
上篇<Spring Boot系列--日志配置>介绍了Spring Boot如何进行日志配置,日志系统用的是Spring Boot默认的LogBack. 事实上,除了使用默认的LogBack ...
- Spring Boot 2.0 整合Thymeleaf 模板引擎
本节将和大家一起实战Spring Boot 2.0 和thymeleaf 模板引擎 1. 创建项目 2. 使用Spring Initlizr 快速创建Spring Boot 应用程序 3. 填写项目配 ...
- 【ELK】4.spring boot 2.X集成ES spring-data-ES 进行CRUD操作 完整版+kibana管理ES的index操作
spring boot 2.X集成ES 进行CRUD操作 完整版 内容包括: ============================================================ ...
- Spring Boot + MyBatis + Druid + Redis + Thymeleaf 整合小结
Spring Boot + MyBatis + Druid + Redis + Thymeleaf 整合小结 这两天闲着没事想利用**Spring Boot**加上阿里的开源数据连接池**Druid* ...
- 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 ...
- 14、Spring Boot 2.x 集成 Druid 数据源
14.Spring Boot 2.x 集成 Druid 数据源 完整源码: Spring-Boot-Demos
随机推荐
- 推荐:【视频教程】ASP.NET Core 3.0 入门
墙裂推荐了,免费,通俗易懂,唯一可惜的就是不是我录的,更可惜的是人家录制完了快半年了我还没看完... 版权归原作者所有,建议新手还是边看边实践吧,要不然过完一遍发现自己啥也没学会,不要眼高手低 [视频 ...
- Linux下安装redis 3.0及C语言中客户端实现demo
1.获取安装文件 wget http://download.redis.io/redis-stable.tar.gz 2.解压文件 tar xzvf redis-stable.tar.gz 3.进入目 ...
- Python--jsonpath
JsonPath是一种信息抽取类库,是从JSON文档中抽取指定信息的工具,提供多种原因实现保本:JavaScript/Python/PHP和Java. 使用方法如: import jsonpathre ...
- WPF入门(4)——资源
引用<深入浅出WPF>对资源的解读: 每个WPF的界面元素都具有一个名为Resources的属性,这个属性继承自FrameworkElement类,其类型为ResourceDictiona ...
- 【C#】上机实验一
1.开发一个控制台应用程序,根据提示从键盘获取一个华氏温度,请转换并输出对应的摄氏温度. using System; namespace Project { class Program { publi ...
- 【贪心】洛谷2019 OI春令营 - 普及组 作业
[P3817 小A的糖果 小A有N个糖果盒,第i个盒中有a[i]颗糖果. 小A每次可以从其中一盒糖果中吃掉一颗,他想知道,要让任意两个相邻的盒子中加起来都只有x颗或以下的糖果,至少得吃掉几颗糖. [贪 ...
- 通过getAdaptiveExtension生成的动态类
通过getAdaptiveExtension生成的动态类 方便调式使用 请放在根目录下
- asp.net core-1.在控制台创建ASP.NET Core应用程序
创建asp.net core应用程序,需要先把环境安装好,我这边选的是vs2017 第一步先执行dotnet 我执行dotnet --help可以把所有的命令全部列出来: 红框内就是我们可以用来初始化 ...
- uboot中打开 debug调试信息的方法
在uboot目录下include/common.h中, 原理:只需要让 _DEBUG 的值为 1即可. 最简单的做法就是在下图第一行之前添加 #define DEBUG
- 103 保序回归 isotonic regression
103 保序回归 isotonic regression 2016-03-30 11:25:27 bea_tree 阅读数 6895 版权声明:本文为博主原创文章,遵循CC 4.0 BY-SA版权 ...