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";
}
}

最新文章

  1. redis 快速入门(win7)
  2. C#语言——类
  3. 使用ViewBag传送数据从控制器至视图
  4. Android应用如何监听自己是否被卸载及卸载反馈功能的实现
  5. 关于Function.prototype.bind
  6. Gradle中ProGuard的配置
  7. html一般标签、常用标签、表格
  8. C/C++堆栈指引(转)
  9. JS(五)
  10. android:versionCode和android:versionName
  11. Ibatis调用存储过程实现增删改以及分页查询
  12. STLport在vc6中的集成
  13. win7系统,apache2.2下添加PHP5的配置详解
  14. [UWP]了解模板化控件(5):VisualState
  15. HDU-5157Harry and magic string
  16. springboot2.0(一):【重磅】Spring Boot 2.0权威发布
  17. OAuth2
  18. .NET开发工程师职业规划
  19. 什么是IIS ?
  20. cannal&amp;otter源码解析

热门文章

  1. es6字符串扩展 -- 字符串长度补全功能 padStart(), padEnd()
  2. re.sub 实现多处替换
  3. fastify nodejs框架
  4. imm自动发现有问题,监控项不再支持
  5. JS的ES5的扩展内容
  6. Python 10 训练模型
  7. MVC框架与增强
  8. 洛谷 P2040 打开所有的灯 题解
  9. nginx.conf 配置解析之文件结构
  10. [Gamma]Scrum Meeting#1