SpringBoot10--引入模板引擎thymeleaf
一、通过场景启动器引入thymeleaf即可
1、引入thymeleaf
<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-thymeleaf</artifactId> </dependency>
2、更改thymeleaf版本
<properties> <thymeleaf.version>3.0.2.RELEASE</thymeleaf.version>
<!--thymeleaf的视图支持器>
<thymeleaf9-layout-dialect.version>2.1.1</thymeleaf9-layout-dialect.version> </properties>
学习的时候使用的是springboot1.5。我自己用的2.3,更改thymeleaf版本有所不同
<properties> <!--这里有所不同--> <thymeleaf-spring5.version>3.0.9.RELEASE</thymeleaf-spring5.version> <thymeleaf-layout-dialect.version>2.3.0</thymeleaf-layout-dialect.version> </properties>
3、使用实例
在classpath:templates/下html文件会被thymeleaf自动渲染。
编写controller处理请求
package com.killbug.helloworld.controller; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.RequestMapping; @Controller public class TestController { @RequestMapping("/success") public String success (){ return "success"; } }
测试: