Kite学习框架的第十六天
1.模板引擎
SpringBoot推荐使用Thymeleaf:语法简单,功能强大
1.1 引入themelead
字spring的官方文档
找到thymelead复制在pom.xml中进行导入
我们导入的是当前spring版本以来的对应的thymelead版本
<!--引入thymeleaf-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
1.2 thymelead的使用
只要我们把html页面放置在classpath:/template/ 下,thymelead就会自动进行渲染
使用方法:
- 导入命名空间
<html lang="en" xmlns:th="http://www.thymeleaf.org">
- thymelead语法
<div id="div01" class="myDiv" th:id="${kite}" th:class="${kite}" th:text="${kite}">
1.3 语法规则
- th:text 改变当前的元素里面的标签内容
- th : 任意的html属性,来替换原来的属性值,例如th:id="${kite},替换id的属性值
- 表达式
***${…}***:获取变量值;OGNL;(使用最多的获取值的方式)
Simple expressions:(表达式语法)
Variable Expressions: ${
...}:获取变量值;OGNL;
1)、获取对象的属性、调用方法
2)、使用内置的基本对象:
#ctx : the context object.
#vars: the context variables.
#locale : the context locale.
#request : (only in Web Contexts) the HttpServletRequest object.
#response : (only in Web Contexts) the HttpServletResponse object.
#session : (only in Web Contexts) the HttpSession ob