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.控制器
@Controllerpublic 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>
转载于:https://www.cnblogs.com/clovejava/p/8111534.html
Thymeleaf的学习相关推荐
- Thymeleaf基础学习之路
赠送thymeleaf3官方文档,英文的,不过也能看明白,大概就是教你怎么取出来文本或者对象然后根据它特定的语法展示出来 链接:https://pan.baidu.com/s/18NrRhgwb231 ...
- Thymeleaf 标签学习 之 th:if 和 th:unless 的使用
一.使用详解 th:if 当条件为true则显示. th:unless 当条件为false 则显示. JAVA代码 @GetMapping(value = "/test") pub ...
- thymeleaf的学习1----------------摸鱼王的日常学习
模板引擎thymeleaf thymeleaf简介 Thymeleaf是一个适用于Web和独立环境的现代服务器端java模板引擎 https://www.thymeleaf.org 为什么要使用thy ...
- Thymeleaf 标签学习 之 th:text 和 th:utext 的使用
一.th:text 和 th:utext 有什么作用? 1.相同点 1.都可以对变量或表达式进行求值 2.用" + "可进行文本连接 2.不同点 当获取从后段传来的参数带有html ...
- SpringBoot-08模板引擎 Thymeleaf 找源码官方文档使用 语法的学习
Thymeleaf 模板引擎 前端交给我们的页面,是html页面.如果是我们以前开发,我们需要把他们转成jsp页面,jsp好处就是当我们查出一些数据转发到JSP页面以后,我们可以用jsp轻松实现数据的 ...
- Shiro学习记录(详细)
文章目录 Shiro学习记录 shiro核心组件 Spring Boot 整合 Shiro Shiro 整合 Thymeleaf Shiro学习记录 什么是 Shiro 官网:http://shiro ...
- SpringBoot学习笔记【基础】
1. SpringBoot Javase:OOP mysql:持久化 html+js+css+jquery+框架=视图,框架不熟练,css不好 javaweb:独立开发MVC三层架构的网站 ssm:框 ...
- springboot学习笔记(未完待续)
微服务阶段 javase: oop mysql:持久化 html + css + js + jquery + 框架 javaweb ssm 微服务:springboot springcloud 程序 ...
- Thymeleaf一篇就够了
目录 什么是Thymeleaf 模板引擎介绍 Thymeleaf介绍 学习Thymeleaf必知的知识点 Springboot MVC介绍 动静分离 第一个Thymeleaf程序 创建程序,添加依赖 ...
- Thymeleaf简介
关于我第一次使用Thymeleaf写模板代码,被折磨这件事- Thymeleaf官网 https://www.thymeleaf.org/ 学习中自然少不了查阅文档,虽然这对于一个英语学渣来说是一件比 ...
最新文章
- led动态显示 c语言,单片机LED点阵的纵向移动(动态显示)
- 使用jMeter构造逻辑上有依赖关系的一系列并发请求
- 全国计算机等级考试题库二级C操作题100套(第85套)
- [转]Excel导入异常Cannot get a text value from a numeric cell解决
- mysql cascade|restrict|no action|set null__mysql 外键的几种约束
- 核心显卡是新一代的智能图形核心
- 一张图理清 Python3 所有知识点
- 不使用第三个变量的情况下,实现两个变量间的互换。
- Opencv学习笔记(2)模块,图像读取、显示、叠加、融合、颜色分离、亮度、对比度
- 判断一个数是否为质数
- 十进制、二进制、八进制、十六进制对照表
- 实验三linux进程并发程序设计,实验三Linux进程并发程序设计.doc
- java severs_openssl简介-指令s_server
- ceph 删除 osd
- 日期比较(substring split prase)
- 4米乘以12米CAD图_建筑专业CAD识图实例讲解
- CATIA达索三维建模软件的功能和核心技术是什么?
- 数值分析笔记(一):方程求根
- 整理了500万+微信红包封面,速抢!
- 华为云CDN加速,让你告别网速慢的烦恼