我们第一步要先引入依赖
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
thymeleaf的使用,我们可以查看官网:https://www.thymeleaf.org/doc/tutorials/3.0/usingthymeleaf.html
导入依赖的时候,我们在template中写的html文件就可以在访问路径中生效了
@RestController
public class hellocontroller {
@RequestMapping("/hello")
public String hello(){
return "hello world";
}
@RequestMapping("/in")
public String test1(){
return "hello";
}
}
这样就可以了
查看thymeleaf可以发现
路径是templates下面的.html文件都可以导入
html中的属性就可以变成了th:属性 进行绑定
比如<div text = ""></div>
就可以变成了<div th:text =${}></div>进行动态绑定
然后就可以在函数中的参数进行绑定model model进行绑定
使用的时候通常配合@Controller来使用