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. Vue.set全局操作

    Vue.set 的作用就是在构造器外部操作构造器内部的数据.属性或者方法.比如在vue构造器内部定义了一个count为1的数据,我们在构造器外部定义了一个方法,要每次点击按钮给值加1.就需要用到Vue ...

  2. 今天就整一个bug了

    BeanPostProcessor加载次序及其对Bean造成的影响分析 SSM整合出现not found for dependency: expected at least 1 bean which ...

  3. IAR中的 identifier "FILE" is undefined 问题

     最近由于希望使用IAR的printf()函数方便进行打印字符,出现IAR报错,即:identifier "FILE" is undefined,问题得以解决.   (1)进行pr ...

  4. 51nod 1275 连续字段的差异(单调队列)

    http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1275 题意: 思路: 固定某个端点,然后去寻找满足能满足要求的最大区间, ...

  5. 1. Mysql在java中的使用步骤

    -1.配置数据库:http://www.cnblogs.com/sshoub/p/4321640.html 2.创建可以远程的登录用户:http://www.cnblogs.com/xyzdw/arc ...

  6. 【一】php 基础知识

    1 php标记,<?php php代码 ?> 2 注释:代码的解释和说明 多行注释 /**/ 单行注释 //.# 3“.”连接符 echo "hello".date(& ...

  7. VC.判断双字节字符集前导字节集(IsDBCSLeadByte)

    ZC:这是 WIndows API 函数 1.“BOOL IsDBCSLeadByte( char );” 判断 某字节是否在 双字节字符集的前导字节集中 ZC:可以判断  如 汉字.日文.韩文等 Z ...

  8. 力扣(LeetCode)709. 转换成小写字母

    实现函数 ToLowerCase(),该函数接收一个字符串参数 str,并将该字符串中的大写字母转换成小写字母,之后返回新的字符串. 示例 1: 输入: "Hello" 输出: & ...

  9. 学习笔记42—Win7下安装Linux双系统

    1.下载Linux镜像:http://mirrors.163.com/ubuntu-releases/18.04.1/ 方法一: 1.用软通牒软件将Linux的镜像写入空的优盘中, 具体如下: 1) ...

  10. Python全栈开发-Day8-Socket网络编程

    本节内容 断言 Socket构建框架 ftp构建框架 Socket粘包 Socket介绍 Socket参数介绍 基本Socket实例 通过Socket实现简单SSH SocketServer 支持多用 ...