1、引入pom依赖

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>

2、设置thymeleaf版本,版本3检查html标签可以没有闭合结束符

    <properties>
<thymeleaf.version>3.0..RELEASE</thymeleaf.version>
<thymeleaf-layout-dialect.version>2.0.</thymeleaf-layout-dialect.version>
</properties>

3、配置文件设置thymeleaf属性

spring.thymeleaf.cache=false
spring.thymeleaf.prefix=classpath:/templates/
spring.thymeleaf.suffix=.html
spring.thymeleaf.encoding=UTF-
spring.thymeleaf.content-type=text/html
spring.thymeleaf.mode=HTML5

4、在resources/templates新建index.html文件

<!DOCTYPE html>
<html lang="en" xmlns="http://www.w3.org/1999/xhtml"
xmlns:th="http://www.thymeleaf.org">
<head>
<title>Hello World!</title>
</head>
<body>
<h1 th:inline="text">Hello</h1>
<p th:text="${hello}"></p>
</body>
</html>

5、编写controller

@RequestMapping
@Controller
public class IndexController { @GetMapping("/helloHtml")
public String testHelloHtml(Model model){
model.addAttribute("hello", "你好");
return "index";
}
}

SpringBoot中使用Thymeleaf模板的更多相关文章

  1. 在Spring MVC和Spring Boot中使用thymeleaf模板

    Spring MVC: POM: <!-- thymeleaf模板 --> <!-- https://mvnrepository.com/artifact/org.thymeleaf ...

  2. 7 — 简单了解springboot中的thymeleaf

    1.官网学习地址 https://www.thymeleaf.org/doc/tutorials/3.0/usingthymeleaf.html 2.什么是thymeleaf? 一张图看明白: 解读: ...

  3. springboot 中的 thymeleaf 页面进阶小知识

    我们做好了登录页,那设计一个场景吧,比如我们登录后跳转到公司主页,想从公司主页再跳转到员工列表页: 这样的场景我们该如何实现,首先要知道一些基础知识,就是SpringBoot的一些关于请求的架构知识: ...

  4. springboot 中使用thymeleaf

    Spring Boot支持FreeMarker.Groovy.Thymeleaf和Mustache四种模板解析引擎,官方推荐使用Thymeleaf. spring-boot-starter-thyme ...

  5. 最简单的 springboot 发送邮件,使用thymeleaf模板

    1,导入需要的包 <dependency> <groupId>org.springframework.boot</groupId> <artifactId&g ...

  6. SpringBoot中的thymeleaf引擎报错

    关于:thymeleaf报错: An error happened during template parsing (template: "class path resource [temp ...

  7. SpringBoot 之Thymeleaf模板.

    一.前言 Thymeleaf 的出现是为了取代 JSP,虽然 JSP 存在了很长时间,并在 Java Web 开发中无处不在,但是它也存在一些缺陷: 1.JSP 最明显的问题在于它看起来像HTML或X ...

  8. Spring Boot2(五):使用Spring Boot结合Thymeleaf模板引擎使用总结

    一.Thymeleaf概述 一般来说,常用的模板引擎有JSP.Velocity.Freemarker.Thymeleaf . SpringBoot推荐的 Thymeleaf – 语法更简单,功能更强大 ...

  9. springboot 引入 thymeleaf 模板

    第一步pom中: <!-- 引入 thymeleaf 模板依赖 --> <dependency> <groupId>org.springframework.boot ...

随机推荐

  1. selenium 2 设置浏览器安装路径

    selenium 2由于调用的是真实的浏览器,所以当你的浏览器不是安装在默认路径下,你就需要设定浏览器启动路径:若是默认路径,则程序中不需设定浏览器启动路径. 比如说用firefox进行测试 1. f ...

  2. PostgreSQL 执行计划

    简介 PostgreSQL是“世界上最先进的开源关系型数据库”.因为出现较晚,所以客户人群基数较MySQL少,但是发展势头很猛,最大优势是完全开源. MySQL是“世界上最流行的开源关系型数据库”.当 ...

  3. Linux中tune2fs命令的-o选项

    debug 启用此文件系统的调试代码. bsdgroups 在创建新文件时模拟BSD行为:它们将使用创建它们的目录.标准系统V的行为是默认情况下,新创建的文件采用当前进程的fsgid,除非目录设置了s ...

  4. Presto Infrastructure at Lyft

    转载一篇关于 lyft presto 平台建设的实践 Overview Early in 2017 we started exploring Presto for OLAP use cases and ...

  5. GoCN每日新闻(2019-11-04)

    GoCN每日新闻(2019-11-04) GoCN每日新闻(2019-11-04)   1. Go中垃圾收集器是如何标记内存的 https://medium.com/a-journey-with-go ...

  6. 修改Docker容器启动配置参数

    有时候,我们创建容器时忘了添加参数 --restart=always ,当 Docker 重启时,容器未能自动启动, 现在要添加该参数怎么办呢,方法有二: 1.Docker 命令修改 docker c ...

  7. 5G 融合计费系统架构设计与实现(一)

    5G 融合计费系统架构设计与实现(一) 随着5G商用临近,5G的各个子系统也在加紧研发调试,本人有兴全程参与5G中的融合计费系统(CCS)的设计.开发.联调工作.接下来将用几篇文章介绍我们在CCS实现 ...

  8. Oracle JDBC prefetch: how to avoid running out of RAM

    Using Oracle java JDBC (ojdbc6 11.2.0.4), loading a query with many rows takes forever (high latency ...

  9. RequireJS - 快速指南

    原文: https://www.tutorialspoint.com/requirejs/requirejs_quick_guide.htm RequireJS - 概述 RequireJS是一个Ja ...

  10. openssl制作证书全过程 + 部分修改

    一:生成CA证书    目前不使用第三方权威机构的CA来认证,自己充当CA的角色.     先决条件:从openssl官网下载www.openssl.org                安装open ...