Spring Boot学习之旅:(十二)模版引擎-Thymeleaf
来源:互联网 发布:唯品会真假知乎 编辑:程序博客网 时间:2024/06/14 10:01
Thymeleaf是个XML/XHTML/HTML5模板引擎,可以用于Web与非Web应用。
Thymeleaf的主要目标在于提供一种可被浏览器正确显示的、格式良好的模板创建方式,因此也可以用作静态建模。你可以使用它创建经过验证的XML与HTML模板。相对于编写逻辑或代码,开发者只需将标签属性添加到模板中即可。接下来,这些标签属性就会在DOM(文档对象模型)上执行预先制定好的逻辑。Thymeleaf的可扩展性也非常棒。你可以使用它定义自己的模板属性集合,这样就可以计算自定义表达式并使用自定义逻辑。这意味着Thymeleaf还可以作为模板引擎框架。
引入依赖
maven中直接引入
<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-thymeleaf</artifactId> </dependency>
配置视图解析器
spring-boot很多配置都有默认配置,比如默认页面映射路径为classpath:/templates/*.html同样静态文件路径为classpath:/static/在application.properties中可以配置thymeleaf模板解析器属性.就像使用springMVC的JSP解析器配置一样
上述是默认路径如果是默认路径可以不写
添加配置
#thymeleaf startspring.thymeleaf.mode=HTML5spring.thymeleaf.encoding=UTF-8spring.thymeleaf.content-type=text/html#开发时关闭缓存,不然没法看到实时页面spring.thymeleaf.cache=false#thymeleaf end
controller
@GetMapping() public String hello(Model model) { model.addAttribute("name", "cxhc"); return "index"; }
页面
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:th="http://www.thymeleaf.org" xmlns:sec="http://www.thymeleaf.org/thymeleaf-extras-springsecurity3"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Hello World!</title> </head> 大家好我是 <span th:text="${name}"></span></html>
启动工程输入
http://localhost:8080/user
更多详细信息请看官网 解释更加详细和权威
http://www.thymeleaf.org/
文章地址:http://www.haha174.top/article/details/252777
源码地址:https://github.com/haha174/boot.git
阅读全文
0 0
- Spring Boot学习之旅:(十二)模版引擎-Thymeleaf
- Spring Boot之旅:Java模版引擎Thymeleaf详解(一)
- Spring Boot学习之旅:(十一)模版引擎-jsp
- Spring Boot学习之旅:(十三)模版引擎-FreeMarker
- Spring Boot 学习11--使用模版Thymeleaf- freemarker
- Spring Boot学习笔记-Thymeleaf模板引擎的配置
- spring Boot thymeleaf模版使用过程
- spring Boot 集成 Thymeleaf模板引擎实例
- (8)spring boot使用thymeleaf模板引擎
- Spring Boot整合Thymeleaf模板引擎
- spring-boot thymeleaf模板学习
- Spring Boot 12之 thymeleaf
- Spring Boot 系列之 thymeleaf
- Spring Boot学习(四)之web开发渲染页面 -- Thymeleaf
- Spring MVC与thymeleaf模版引擎集成的简单例子
- 深入学习spring-boot系列(三)--使用thymeleaf模板
- Spring-Boot初学之配置文件application.properties(thymeleaf模板)
- Spring Boot学习记录(二)--thymeleaf模板
- 前端基础(4):html语法(3): <input> 标签
- 双目相机标定之OpenCV获取左右相机图像+MATLAB单目标定+双目标定
- Codeforces887C-Solution for Cube
- jquery validate 手机号码、电话号码验证
- 已知二叉树的中序遍历和前序遍历,如何求后序遍历
- Spring Boot学习之旅:(十二)模版引擎-Thymeleaf
- MySQL必知必会_条件查询
- C 头文件
- 分治算法--士兵排队(poj1723)
- 内核的工作流程(流程图表示)
- SDN 下用ODL实现QoS保障(1)-环境搭建
- Linux入门笔记5. 多用户多任务
- 由于fstab文件中挂接选项引起的系统不能启动
- 删除数组中所有给定的数字。