其实Thymleaf与jsp一样都是一个模板引擎,都可以动态的写入值,与后端进行交互,但是springboot并不支持jsp,所以我们需要学习Thymeleaf
要用Thymeleaf 就需要引用依赖
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
然后就是一些它的一些表达式语句
Variable Expressions: ${...}:获取变量值;OGNL;
Selection Variable Expressions: *{...}:选择表达式:和${}在功能上是一样;
Message Expressions: #{...}:获取国际化内容
Link URL Expressions: @{...}:定义URL;
Fragment Expressions: ~{...}:片段引用表达段
下面我们就写一个页面进行体会(注意我们的thymeleaf页面需要写在resoucers下的templates下,后面我会讲一下为什么
controller层如下图
thymleaf页面如下(即所要跳转的star.html页面)
展示页面如下