Thymeleaf是一个java类库,是一个xml/xhtml/html5的模板引擎,可以作为mvc的web应用的view层。
Thymeleaf提供了额外的模块与Spring MVC集成,所以我们可以使用Thymeleaf完全替代jsp。

Spring Boot默认就是使用thymeleaf模板引擎的,所以只需要在pom.xml加入依赖即可。

<!-- thymeleaf模板引擎  -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>

Thymeleaf缓存在开发过程中,肯定是不行的,那么就要在开发的时候把缓存关闭,只需要在application.properties进行配置即可:

# thymeleaf Config
spring.thymeleaf.cache=false

根据SpringBoot默认原则,脚本样式,图片等静态文件应放置在src/main/resources/static下,可以引入Bootstrap和jQuery。

编写模板文件src/main/resouces/templates/hello.html,在html文件中引入<html xmlns:th="http://www.thymeleaf.org">即变为thymeleaf

<!DOCTYPE HTML>
<html xmlns:th="http://www.thymeleaf.org">
<head>
<title>Getting Started: Serving Web Content</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
</head>
<body>
<p th:text="'Hello, ' + ${hello} + '!'" />
</body>
</html>

编写访问路径(com.holy.backoa.online.controller):

package com.holy.backoa.online.controller;

import java.util.Map;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping; /**
* 模板测试.
* @author Administrator
*
*/
@Controller
publicclass TemplateController { /**
* 返回html模板.
*/
@RequestMapping("/hello")
public String hello(Map<String,Object> map){
map.put("hello","from TemplateController.hello");
return"/hello";
} }

启动应用,输入地址:http://127.0.0.1:8080/hello 会输出:

Hello,from TemplateController.hello

Spring Boot集成Thymeleaf的更多相关文章

  1. Spring Boot 集成 thymeleaf 模版引擎

    Spring Boot 建议使用 HTML 来完成动态页面.Spring Boot 提供了大量的模版引擎,包括 Thymeleaf.FreeMarker.Velocity等. Spring Boot ...

  2. spring boot 集成 thymeleaf

    例如meta标签,低版本标签必须要闭合,高版本不用这么严格. pom文件引入高版本jar包如下,propertis里添加:

  3. spring boot 集成Thymeleaf

                                           

  4. Spring Boot整合 Thymeleaf 模板引擎

    什么是Thymeleaf Thymeleaf是一款用于渲染XML.XHTML.HTML5内容的模板引擎.类似Velocity,FreeMaker模板引擎,它也可以轻易的与Spring MVC等Web框 ...

  5. 【实验一 】Spring Boot 集成 hibernate & JPA

    转眼间,2018年的十二分之一都快过完了,忙于各类事情,博客也都快一个月没更新了.今天我们继续来学习Springboot对象持久化. 首先JPA是Java持久化API,定义了一系列对象持久化的标准,而 ...

  6. 77. Spring Boot Use Thymeleaf 3【从零开始学Spring Boot】

    [原创文章,转载请注明出处] Spring Boot默认选择的Thymeleaf是2.0版本的,那么如果我们就想要使用3.0版本或者说指定版本呢,那么怎么操作呢?在这里要说明下 3.0的配置在spri ...

  7. spring boot 集成 websocket 实现消息主动推送

    spring boot 集成 websocket 实现消息主动 前言 http协议是无状态协议,每次请求都不知道前面发生了什么,而且只可以由浏览器端请求服务器端,而不能由服务器去主动通知浏览器端,是单 ...

  8. Spring Boot整合Thymeleaf模板引擎

    什么是Thymeleaf Thymeleaf是一款用于渲染XML.XHTML.HTML5内容的模板引擎.类似Velocity,FreeMaker模板引擎,它也可以轻易的与Spring MVC等Web框 ...

  9. Spring Boot集成Shrio实现权限管理

    Spring Boot集成Shrio实现权限管理   项目地址:https://gitee.com/dsxiecn/spring-boot-shiro.git   Apache Shiro是一个强大且 ...

随机推荐

  1. Hexo搭建(VPS)

    都说 hexo 是静态的 Blog,当时不明觉厉= =.后来终于知道了什么意思......所谓的静态,其实就是因为你不能改云端,而是依赖本地数据,然后使用命令将本地数据变成 web 数据再使用浏览器进 ...

  2. Python.错误解决:scrapy 没有crawl 命令

    确保2点: 1.把爬虫.py复制到spiders文件夹里 如执行scrapy crawl demo ,spiders里面就要有demo.py文件 2.在项目文件夹内执行命令 在scrapy.cfg所在 ...

  3. Centos7安装配置Apache+PHP+Mysql+phpmyadmin

    转载自: Centos7安装配置Apache+PHP+Mysql+phpmyadmin 一.安装Apache yum install httpd 安装成功后,Apache操作命令: systemctl ...

  4. python类与类的关系

    类与类之间的关系(依赖关系,大象与冰箱是依赖关系) class DaXiang: def open(self, bx): # 这里是依赖关系. 想执行这个动作. 必须传递一个bx print(&quo ...

  5. strtotime 获取之前,之后时间

    一年之前 <?php echo strtotime('-1 year'); ?> 一年之后 <?php echo strtotime('+1 year'); ?> 一月之前 & ...

  6. php中if(\$a==\$b)和if(\$a=\$b)什么区别?

    <?php // if($a==$b)和if($a=$b)什么区别? $a = 1; $b = 1; if ($a == $b) { // 通过 echo '通过'.PHP_EOL; } if ...

  7. Java SE LinkedList的底层实现

    关于实现链表的底层原理 链表便于增删,不便于查询 package com.littlepage.linkedList; /** * 基于底层实现LinkedList * @author Littlep ...

  8. C/C++.文件是否存在

    1. 2._access, _waccess.html(https://msdn.microsoft.com/en-us/library/1w06ktdy.aspx) int _access( con ...

  9. rm

    rm [选项]... 目录... 删除指定的<文件>(即解除链接). -d      --directory    删除可能仍有数据的目录 (只限超级用户)-f      --force  ...

  10. System.out.println 报错: 只能运行在方法体内哦, 类里面只包含属性和方法哦,注意!

    类里面包含属性和方法 所以, System.out.println,只能放在方法体内运行,不能放在类里.方法外哦