Thymeleaf的学习
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的学习的更多相关文章
- Thymeleaf标签学习
目录 Thymeleaf Thymeleaf的特点 SpringBoot与之整合 Thymeleaf常用语法 变量_变量案列 变量_动静结合 变量_ognl表达式的语法糖 变量_自定义变量 方法 方法 ...
- SSM框架——thymeleaf学习总结
本人关于thymeleaf的学习源自: https://www.bilibili.com/video/BV1qy4y117qi 1.thymeleaf的项目搭建 首先创建springboot项目,相关 ...
- Thymeleaf从入门到精通
什么是Thymeleaf 大家好,我是bigsai,今天我们来学习Thymeleaf,如果你对Thymeleaf比较陌生也不要紧,它很容易学习与理解,并有着自己鲜明的特色. 开始之前,我们依旧问一个问 ...
- SpringBoot-06-模板引擎Thymeleaf
6. 模板引擎 Thymeleaf Thyme leaf 英译为 百里香的叶子. 模板引擎 以前开发中使用的jsp就是一个模板引擎,但是springboot 以jar的方式,并且使用嵌入式的tom ...
- 狂神说SpringBoot11:Thymeleaf模板引擎
狂神说SpringBoot系列连载课程,通俗易懂,基于SpringBoot2.2.5版本,欢迎各位狂粉转发关注学习. 微信公众号:狂神说(首发) Bilibili:狂神说Java(视频) 未经作 ...
- springBoot入门到精通-Simple
https://blog.csdn.net/zhiyikeji/article/details/84346189 1.springBoot前期准备 1.环境配置:jdk,maven 2.编写工具:st ...
- SpringBoot-Thymeleaf模板引擎
模板引擎,我们其实大家听到很多,其实jsp就是一个模板引擎,还有用的比较多的freemarker,包括SpringBoot给我们推荐的Thymeleaf,模板引擎有非常多,但再多的模板引擎,他们的思想 ...
- SpringBoot详解
1.Hello,World! 1.1.SpringBoot简介 回顾什么是Spring Spring是一个开源框架,2003 年兴起的一个轻量级的Java 开发框架,作者:Rod Johnson . ...
- Spring Boot 学习笔记--整合Thymeleaf
1.新建Spring Boot项目 添加spring-boot-starter-thymeleaf依赖 <dependency> <groupId>org.springfram ...
随机推荐
- 【NOI2019模拟2019.6.29】字符串(SA|SAM+主席树)
Description: 1<=n<=5e4 题解: 考虑\(f\)这个东西应该是怎样算的? 不妨建出SA,然后按height从大到小启发式合并,显然只有相邻的才可能成为最优答案.这样的只 ...
- PHP FILTER_VALIDATE_EMAIL 过滤器
定义和用法 FILTER_VALIDATE_EMAIL 过滤器把值作为 e-mail 地址来验证. Name: "validate_email" ID-number: 274 实例 ...
- Android中当数据库需要更新时我们该怎么办?
问题:Android数据库更新并保留原来的数据如何实现 Andoird的SQLiteOpenHelper类中有一个onUpgrade方法.帮助文档中只是说当数据库升级时该方法被触发.经过实践,解决了我 ...
- 2018.12.26 考试(哈希,二分,状压dp)
T1 传送门 解题思路 发现有一个限制是每个字母都必须相等,那么就可以转化成首尾的差值相等,然后就可以求出\(k-1\)位的差值\(hash\)一下.\(k\)为字符集大小,时间复杂度为\(O(nk) ...
- js——private 私有方法公有化
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- TI低功耗蓝牙(BLE)介绍【转】
转自:http://blog.csdn.net/ooakk/article/details/7302425 TI低功耗蓝牙(BLE)介绍 本文档翻译和修改自参考资料:CC2540Bluetooth L ...
- CSS:CSS 文本格式
ylbtech-CSS:CSS 文本格式 1.返回顶部 1. CSS 文本格式 文本格式 This text is styled with some of the text formatting pr ...
- (52) C# 串口通讯
一.串口通讯基本参数 1.波特率:每秒传输n个多少个二进制位. 例如 9600 b/s = 1200 B/s= 1.172KB/S 2.传输数据格式 数据格式由起始位(start bit).数据位 ...
- C++——类
1.类和结构体,只有的默认访问权限的区别 2.类内不能定义和类外类型名相同的类型名.为什么?typedef机制? typedef double money; class Account { priva ...
- Apache配置 PHP 支持
1,在服务区安装PHP 解压 php 到纯英文路径目 2,添加 PHP处理模块 LoadModule php7_module C:/ProgramData/php/php7apache2_4.dl 3 ...