Thymeleaf
- Thymeleaf完全遵循H5规范。
- SpringBoot推荐使用Thymeleaf代替JSP作为显示层。
- 使用Thymeleaf要加入依赖
Thymeleaf规范
- H5中标签都有 ‘/’ 结尾、否则会报错,那Thymeleaf不想这么严谨,就需要加入nokehtml依赖,并在全局配置文件application.properties中添加属性:spring.thymeleaf.mode=LEGACYHTML5
<dependency>
<groupId>net.sourceforge.nekohtml</groupId>
<artifactId>nekohtml</artifactId>
<version>1.9.22</version>
</dependency>
- Thymeleaf是以html的形式放在templates目录下的
- Thymeleaf完全遵循了MVC规范,不能直接访问到,只能通过转发到Thymeleaf
控制器转发到Thymeleaf
转发有两种方式
- 1.返回一个字符串,路径上可以不加 '/'
@RequestMapping("/index")
public String forwardToIndexHtml(){
return "index";
}
</