Spring Boot集成Thymeleaf
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的更多相关文章
- Spring Boot 集成 thymeleaf 模版引擎
Spring Boot 建议使用 HTML 来完成动态页面.Spring Boot 提供了大量的模版引擎,包括 Thymeleaf.FreeMarker.Velocity等. Spring Boot ...
- spring boot 集成 thymeleaf
例如meta标签,低版本标签必须要闭合,高版本不用这么严格. pom文件引入高版本jar包如下,propertis里添加:
- spring boot 集成Thymeleaf
- Spring Boot整合 Thymeleaf 模板引擎
什么是Thymeleaf Thymeleaf是一款用于渲染XML.XHTML.HTML5内容的模板引擎.类似Velocity,FreeMaker模板引擎,它也可以轻易的与Spring MVC等Web框 ...
- 【实验一 】Spring Boot 集成 hibernate & JPA
转眼间,2018年的十二分之一都快过完了,忙于各类事情,博客也都快一个月没更新了.今天我们继续来学习Springboot对象持久化. 首先JPA是Java持久化API,定义了一系列对象持久化的标准,而 ...
- 77. Spring Boot Use Thymeleaf 3【从零开始学Spring Boot】
[原创文章,转载请注明出处] Spring Boot默认选择的Thymeleaf是2.0版本的,那么如果我们就想要使用3.0版本或者说指定版本呢,那么怎么操作呢?在这里要说明下 3.0的配置在spri ...
- spring boot 集成 websocket 实现消息主动推送
spring boot 集成 websocket 实现消息主动 前言 http协议是无状态协议,每次请求都不知道前面发生了什么,而且只可以由浏览器端请求服务器端,而不能由服务器去主动通知浏览器端,是单 ...
- Spring Boot整合Thymeleaf模板引擎
什么是Thymeleaf Thymeleaf是一款用于渲染XML.XHTML.HTML5内容的模板引擎.类似Velocity,FreeMaker模板引擎,它也可以轻易的与Spring MVC等Web框 ...
- Spring Boot集成Shrio实现权限管理
Spring Boot集成Shrio实现权限管理 项目地址:https://gitee.com/dsxiecn/spring-boot-shiro.git Apache Shiro是一个强大且 ...
随机推荐
- Oracle 基础学习笔记
知识点 一.登陆数据库: 登陆数据库: sqlplus system/oracle123456 二.新建用户.授权(连接数据库.创建表.表空间.查询某用户下的表) 语法: create user [用 ...
- SQLite EF Core Database Provider
原文链接 This database provider allows Entity Framework Core to be used with SQLite. The provider is mai ...
- mybatis批量更新数据参考
https://blog.csdn.net/xyjawq1/article/details/74129316
- RN 调用安卓的原生方法(实现Toast效果)
首先明确一点,坑实在是是太多了-神奇呀! ok! 基本思路: 1.用AS打开一个已经存在的项目(这里可以打开项目中的android也可以是android里面的build.gradle) 2.在AS里新 ...
- 在JAVA中返回类型使用泛型T和Object有什么区别?
最近在读jackson源码的时候发现有段代码返回类型写的是<T> T,而我自己一般写的是Object.上网搜了下这个语法糖,在stackoverflow上找到一个比较简单易懂的解释,搬运过 ...
- go helloworld
// Sample program to show how a bytes.Buffer can also be used // with the io.Copy function. package ...
- base64 加密原理 解密原理
假设需要加密的字符串是Jasmine 具体转换步骤: 第一步 将待转换的字符串转为一个个字符第二步 计算每一个字符对应的ASCII码十进制第三步 计算出十进制对应的二进制,若不足8位,在前面添加0进行 ...
- AjaxHandler
概要 AjaxHandler组件是在ASP.NET MVC Web应用程序中实现ajax功能的一系列扩展方法,该组件的最初的实现方法借鉴了网上流行的部分源代码, ,经过博主不断完善和改进后推出的比较成 ...
- tkinter 打包成exe可执行文件
1.安装pyinstaller pip install pyinstaller 2.打包 打开cmd,切换到需要打包的文件(demo.py)目录.执行 pyinstaller -F -w demo.p ...
- JqueryValidate 表单验证插件
1.适用场景 表单 ( 支持自定义规则 ) 2.相关文章 jQuery Validate 3.实际问题 JqueryValidate表单相同Name不校验问题解决