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
随机推荐
- java访问磁盘文件
转载,务必写上原文链接 !(尊重与你分享知识的人) 目录 文件 File 对象 VS FileDescriptor 对象 文件讲解java访问磁盘文件过程 fileReader.read() 图解ja ...
- 使用 jsvc 启动tomcat(使用普通用户运行)
使用 jsvc 启动tomcat(使用普通用户运行) jsvc简介 在生产中,tomcat应该以daemon的模式运行,而且如果需要以普通用户的身份启动tomcat,那么就不能使用1024以下的端口, ...
- Asp.net core 学习笔记 2.2 migration to 3.0
Ef core 3.0 一些要注意的改变 refer : https://docs.microsoft.com/en-us/ef/core/what-is-new/ef-core-3.0/breaki ...
- Session共享问题---理论
随着网站访问量增加,初期的一台服务器已经完全不能支持业务,这个时候我们就需要增加服务器设备,来抗住请求的增量,如下所示: 负载均衡的目的本来就是要为了平均分配请求,所以没有固定第一次访问和第二次访问的 ...
- (七)mybatis之多对一关系(复杂)
一.需求分析 需求:查询所有消费者信息,关联查询订单及商品信息,订单明细信息中关联查询查商品信息. 分析:一个消费者有多条订单,一条订单只有一个消费者但是有多条订单明细,一条订单明细只有一个商品信息. ...
- JS密码强度检测
//校验密码强度---沒有匹配到以下級別就提示 function checkPassWord(value){ // 0: 表示第一个级别 1:表示第二个级别 2:表示第三个级别 // 3: 表示第四个 ...
- [LeetCode] 17. 电话号码的字母组合 ☆☆☆(回溯) ###
描述 给定一个仅包含数字 2-9 的字符串,返回所有它能表示的字母组合. 给出数字到字母的映射如下(与电话按键相同).注意 1 不对应任何字母. 示例: 输入:"23"输出:[&q ...
- TDDL生成全局ID原理
TDDL 在分布式下的SEQUENCE原理 TDDL大家应该很熟悉了,淘宝分布式数据层.很好的为我们实现了分库分表.Master/Salve.动态数据源配置等功能. 那么分布式之后,数据库自增序列肯定 ...
- 【Distributed】分布式配置中心
一.概述 1.1 什么是分布式配置中心 常用分布式配置中心框架 二.Apollo阿波罗 2.1 Apollo特点 2.2 Apollo整体架构原理 2.3 Apollo Portol 环境搭建 Lin ...
- zabbix监控MySQL,Tomcat及配置邮件报警
目录 一.思路 二.部署.配置 环境 安装zabbix 对zabbix进行初步优化 添加监控主机 部署监控Tomcat 配置邮件报警 三.总结 一.思路 首先搭建zabbixserver,本机需要安装 ...