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. 学习:STL_vector容器

    vector基本概念: 功能: vector数据结构和数组非常相似,也称为单端数组 vector与普通数组区别: 不同之处在于数组是静态空间,而vector可以动态扩展 动态扩展: 并不是在原空间之后 ...

  2. log4j.properties的配置信息

    吃了没日志的亏,以前总以为日志没用,以后要重视起来了,很多错误服务器不会显示,但是页面上就是出错,这个时候就要显示日志了. 日志的代码如下,创建日志文件,文件名为log4j.properties,把这 ...

  3. 大文件上传控件webupload插件

    之前仿造uploadify写了一个HTML5版的文件上传插件,没看过的朋友可以点此先看一下~得到了不少朋友的好评,我自己也用在了项目中,不论是用户头像上传,还是各种媒体文件的上传,以及各种个性的业务需 ...

  4. 用户管理命令——useradd、paaswd、who、w

    1.useradd和passwd命令: 其中:useradd用来添加用户,passwd用来添加用的的密码: 用户创建后可以用用户名和密码进行登录. 2.passwd:密码的更改: (1)普通用户: 只 ...

  5. ImportError: cannot import name 'DjangoSuitConfig'

    pip3.6 install https://github.com/darklow/django-suit/tarball/v2

  6. 集合类 Map接口 HashTable

    集合类的另外一种重要实现为Map接口,Map接口提供的方法如下: Map接口一个不常见实现为HashTable,HashTable对所有有并发访问问题的方法通过 synchronized 关键字进行并 ...

  7. /etc/resolv.conf文件中的search项作用

    resolv.conf文件中有search项时,主机名解析规则顺序: DNS配置文件如下: # vi /etc/resolv.conf # Generated by NetworkManager se ...

  8. RNN 权重共享

    之前在几篇博客中说到了权重共享,但都觉得不够全面,这里做个专题,以后有新的理解都在此更新. 1. 减少运算只是锦上添花之前说到权重共享可以减少运算,是的,但这样说好像是可有可无,只是运算量大小的问题, ...

  9. dashi 成长 > 领导 > 平台 > 钱 人品 态度 能力 价值

    https://promotion.aliyun.com/ntms/yunparter/invite.html?userCode=thy3557s https://www.aliyun.com/min ...

  10. <c:forEach>, <c:forTokens> 标签

    这些标签封装了Java中的for,while,do-while循环. 相比而言,<c:forEach>标签是更加通用的标签,因为它迭代一个集合中的对象. <c:forTokens&g ...