1.引入依赖

maven中直接引入

  1. <dependency>
  2. <groupId>org.springframework.boot</groupId>
  3. <artifactId>spring-boot-starter-thymeleaf</artifactId>
  4. </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解析器配置一样

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

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

3.编写DEMO

1.控制器

  1. @Controller
  2. public class HelloController {
  3.  
  4. private Logger logger = LoggerFactory.getLogger(HelloController.class);
  5. /**
  6. * 测试hello
  7. * @return
  8. */
  9. @RequestMapping(value = "/hello",method = RequestMethod.GET)
  10. public String hello(Model model) {
  11. model.addAttribute("name", "Dear");
  12. return "hello";
  13. }
  14.  
  15. }

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

  1. <!DOCTYPE HTML>
  2. <html xmlns:th="http://www.thymeleaf.org">
  3. <head>
  4. <title>hello</title>
  5. <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
  6. </head>
  7. <body>
  8. <!--/*@thymesVar id="name" type="java.lang.String"*/-->
  9. <p th:text="'Hello!, ' + ${name} + '!'" >3333</p>
  10. </body>
  11. </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. Vue学习笔记【18】——Vue中的动画(使用过渡类名)

    为什么要有动画:动画能够提高用户的体验,帮助用户更好的理解页面中的功能: 使用过渡类名 步骤分析  需求: 点击按钮,让 h3 显示,再点击,让 h3 隐藏  1. 使用 transition 元素, ...

  2. (抓)ubuntu下安装mysql --- 我主要参考的文章

    转:http://cycnet.blog.51cto.com/117809/812625 现在的软件越来越好安装,尤其是在ubuntu下安装软件,更是没有技巧,只需要在联网的情况下使用apt-get ...

  3. java-Eclipse中使用JDBC连接数据库及相关操作

    准备工作:mysql-connector-java-5.1.6-bin.jar配置 package com.job; import java.sql.Connection; import java.s ...

  4. Windows下安装PIL进行图像处理

    过程一波三折 参考 http://blog.csdn.net/zxia1/article/details/8254113 http://stackoverflow.com/questions/3544 ...

  5. PHPStorm IDE 快捷键(MAC版)

    ⌘——Command ⌃ ——Control ⌥——Option/Alt ⇧——Shift ⇪——Caps Lock fn——功能键就是fn 编辑 Command+alt+T 用 (if..else, ...

  6. rmq +二分暴力 hdu 5726

    参考博客 题意:n 个数字的数列,有m个询问:求出  L   到   R 的  gcd(最大公约数 ),然后问这整个序列中有多少个区间的  gcd  和这个一样. 分析:L 到  R的gcd直接用RM ...

  7. vue 在微信中设置动态标题

    1.安装插件 cnpm install vue-wechat-title --save 2.在main.js中引入 import VueWechatTitle from 'vue-wechat-tit ...

  8. ArcGis基础——Excel表格插入ArcMap布局视图,记录显示不全的替代解决方法

    前几天帮朋友处理了这样一个问题 Excel有200余行记录,插入到ArcMap布局视图,只能显示100行左右. 解决思路 ArcMap要素类的属性表可以插入到布局视图,可否把Excel挂接到要素类的属 ...

  9. javascript中的insertBefore方法

    <SCRIPT LANGUAGE="JavaScript"> window.onload=function(){ var a =document.createEleme ...

  10. tp6 控制器不存在:app\index\controller\Index

    tp6 控制器不存在:app\index\controller\Index config/app.php 修改如下 'auto_multi_app' => true,