1.引入依赖

maven中直接引入

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

可以查看依赖关系,发现spring-boot-starter-thymeleaf下面已经包括了spring-boot-starter-web,所以可以把spring-boot-starter-web的依赖去掉.

2.配置视图解析器

spring-boot很多配置都有默认配置,比如默认页面映射路径为 
classpath:/templates/*.html 
同样静态文件路径为 
classpath:/static/

在application.properties中可以配置thymeleaf模板解析器属性.就像使用springMVC的JSP解析器配置一样

#thymeleaf start
spring.thymeleaf.mode=HTML5
spring.thymeleaf.encoding=UTF-8
spring.thymeleaf.content-type=text/html
#开发时关闭缓存,不然没法看到实时页面
spring.thymeleaf.cache=false
#thymeleaf end

具体可以配置的参数可以查看 
org.springframework.boot.autoconfigure.thymeleaf.ThymeleafProperties这个类,上面的配置实际上就是注入到该类中的属性值.

3.编写DEMO

1.控制器

@Controller
public class HelloController { private Logger logger = LoggerFactory.getLogger(HelloController.class);
/**
* 测试hello
* @return
*/
@RequestMapping(value = "/hello",method = RequestMethod.GET)
public String hello(Model model) {
model.addAttribute("name", "Dear");
return "hello";
} }

2.view(注释为IDEA生成的索引,便于IDEA补全)

<!DOCTYPE HTML>
<html xmlns:th="http://www.thymeleaf.org">
<head>
<title>hello</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
</head>
<body>
<!--/*@thymesVar id="name" type="java.lang.String"*/-->
<p th:text="'Hello!, ' + ${name} + '!'" >3333</p>
</body>
</html>

Thymeleaf的学习的更多相关文章

  1. Thymeleaf标签学习

    目录 Thymeleaf Thymeleaf的特点 SpringBoot与之整合 Thymeleaf常用语法 变量_变量案列 变量_动静结合 变量_ognl表达式的语法糖 变量_自定义变量 方法 方法 ...

  2. SSM框架——thymeleaf学习总结

    本人关于thymeleaf的学习源自: https://www.bilibili.com/video/BV1qy4y117qi 1.thymeleaf的项目搭建 首先创建springboot项目,相关 ...

  3. Thymeleaf从入门到精通

    什么是Thymeleaf 大家好,我是bigsai,今天我们来学习Thymeleaf,如果你对Thymeleaf比较陌生也不要紧,它很容易学习与理解,并有着自己鲜明的特色. 开始之前,我们依旧问一个问 ...

  4. SpringBoot-06-模板引擎Thymeleaf

    6. 模板引擎 Thymeleaf Thyme leaf 英译为 百里香的叶子. 模板引擎 ​ 以前开发中使用的jsp就是一个模板引擎,但是springboot 以jar的方式,并且使用嵌入式的tom ...

  5. 狂神说SpringBoot11:Thymeleaf模板引擎

    狂神说SpringBoot系列连载课程,通俗易懂,基于SpringBoot2.2.5版本,欢迎各位狂粉转发关注学习. 微信公众号:狂神说(首发)    Bilibili:狂神说Java(视频) 未经作 ...

  6. springBoot入门到精通-Simple

    https://blog.csdn.net/zhiyikeji/article/details/84346189 1.springBoot前期准备 1.环境配置:jdk,maven 2.编写工具:st ...

  7. SpringBoot-Thymeleaf模板引擎

    模板引擎,我们其实大家听到很多,其实jsp就是一个模板引擎,还有用的比较多的freemarker,包括SpringBoot给我们推荐的Thymeleaf,模板引擎有非常多,但再多的模板引擎,他们的思想 ...

  8. SpringBoot详解

    1.Hello,World! 1.1.SpringBoot简介 回顾什么是Spring Spring是一个开源框架,2003 年兴起的一个轻量级的Java 开发框架,作者:Rod Johnson . ...

  9. Spring Boot 学习笔记--整合Thymeleaf

    1.新建Spring Boot项目 添加spring-boot-starter-thymeleaf依赖 <dependency> <groupId>org.springfram ...

随机推荐

  1. Vue2.0源码思维导图-------------Vue 初始化

    上一节看完<Vue源码思维导图-------------Vue 构造函数.原型.静态属性和方法>,这节将会以new Vue()为入口,大体看下 this._init()要做的事情. fun ...

  2. [SDOI2010]地精部落 题解

    Description 传说很久以前,大地上居住着一种神秘的生物:地精. 地精喜欢住在连绵不绝的山脉中.具体地说,一座长度为 N 的山脉 H可分 为从左到右的 N 段,每段有一个独一无二的高度 Hi, ...

  3. ES6十大特性(转载CSDN)

    1. const和let关键字 const用于定义常量. let用于定义变量.但是JavaScript中不是已经有变量了吗? 是的,这很正确,但用var声明的变量具有函数作用域,并会被提升到顶部. 这 ...

  4. PowerDesigner(数据库迁移)

    PowerDesigner:导出SQL脚本以及问题解决在PowerDesigner中点击DataBase -----------> Generate Datebase -----(可以点击Pre ...

  5. Dubbo入门到精通学习笔记(五):持续集成管理平台之sonarqube代码质量管理平台的介绍与安装

    文章目录 SonarQube的介绍 SonarQube的安装 安装简介 详细安装过程 详细使用过程 SonarQube的介绍 SonarQube是一个管理代码质量的开放平台. 可以从七个维度检测代码质 ...

  6. Android Telephony分析(六) ---- 接口扩展(实践篇)

    本文将结合前面五篇文章所讲解的知识,综合起来,实现一个接口扩展的功能.如果还没有阅读过前面五篇文章的内容,请先阅读:<Android Telephony分析(一) — Phone详解 >& ...

  7. pytest_按标记执行

    import pytest@pytest.mark.webtestdef test_send_http(): pass @pytest.mark.apptestdef test_devide(): p ...

  8. 前端 JavaScript 基础

    内容目录: 一.JavaScript介绍 二.基础语法   2.1 变量   2.2 数据类型   2.3 流程控制   2.5 函数的全局变量和局部变量   2.6 作用域   2.7 词法分析   ...

  9. windows7远程连接服务器出现身份验证错误,又找不到加密Oracle修正

    把以下内容复制到文本中, Windows Registry Editor Version 5.00 [HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\Cur ...

  10. Pregel Aggregator