Spring Boot模板引擎
来源:互联网 发布:怎么快速提升淘宝星级 编辑:程序博客网 时间:2024/04/25 19:21
Spring Boot 提供了大量模板引擎,包含括 FreeMarker、Groovy、Thymeleaf、Velocity 和 Mustache,Spring Boot 中推荐使用 Thymeleaf 作为模板引擎,它 提供了完美的 Spring MVC 的支持。
------------------------------------------------------------------------
Thymeleaf 基础知识:
它是一个 Java 类库,是一个 xml/xhtml/html5 的模板引擎,可作为 MVC Web 应用的 View 层。还提供了额外的模板与 Spring MVC 集成,可以使用 Thymeleaf 完全替代 JSP。
------------------------------------------------------------------------
使用示例:
1、引入 Thymeleaf
在html标签中使用 xmlns:th=http://www.thymeleaf.org 引入,将页面转换为动态的视图,需要进行动态处理的元素将使用 “th:” 为前缀。
使用“@{}” 引用 Web 静态资源。示例:
<link th:src="@{css/demo.css}" rel="stylesheet"/>
2、访问 model 中的数据
通过“${}” 访问 model 中的属性。示例:<span th:text="${bean.属性}"></span>,需要处理的动态内容需要添加“th:”前缀。
3、model 中的数据迭代
使用 th:each 来做循环迭代, th:each="person:${person}" ,person 作为迭代元素来使用,然后通过 上述示例访问元素。
4、数据判断
通过 ${not#lists.isEmpty(元素)} 表达式判断 元素 是否为空,支持 >、<、>=、<=、==、!=作为比较条件,也支持 SpringEL 表达式语言用于条件中。
5、在 JavaScript 中访问 model
通过在 script 标签中使用 th:inline="javascript",这样 JavaScript 代码即可访问 model中的属性,使用 “[[${}]]” 格式获得实际的值。示例:
<script th:inline="javascript"> var result = [[${model}]] console.log(result.name);</script>在需要 html 的代码中访问 model 中的属性时,使用 th:onlick="'get(\'\+${对象.属性}+'\');'"
6、更多知识,请查看 Thymeleaf官网:http://www.thymeleaf.org
- Spring Boot模板引擎
- Spring Boot整合模板引擎
- spring Boot 集成 Thymeleaf模板引擎实例
- (8)spring boot使用thymeleaf模板引擎
- (9) spring boot使用freemarker模板引擎
- (10) spring boot使用模板引擎总结
- Spring boot集成Httl模板引擎
- spring boot使用模板引擎总结
- Spring Boot整合Thymeleaf模板引擎
- Spring Boot基础6-web应用开发-模板引擎FreeMarker
- Spring Boot基础7-web应用开发-模板引擎Thymeleaf
- Spring Boot基础教程8-web应用开发-模板引擎jsp
- Spring Boot学习笔记-Thymeleaf模板引擎的配置
- Spring Boot基础知识(四)----springMVC与模板引擎
- spring-boot配置html模板引擎freemarker、thymeleaf
- 第7章 Spring Boot集成模板引擎
- Spring Boot整合模板引擎freemarker以及servlet
- spring- boot 发送邮件接口+freemarker视图模板引擎
- 第十二周 【项目
- Android 蓝牙键盘快捷键
- 数据结构实验之排序五:归并求逆序数
- IT行业与风投
- JavaScript中的数组创建
- Spring Boot模板引擎
- mybatise一对多关系查询时不能直接分页
- [LeetCode-Algorithms-147] "Insertion Sort List" (2017.12.21-WEEK16)
- AsyncTask
- iOS——中使用多个Target去管理环境版本
- C# NPOI MO工具的应用(excel,ppt,doc)
- react 随手记
- node.js全局对象和全局变量
- 【重磅发布】《2017开发者调查报告》代码谱写传奇,深度揭秘中国开发者现状