首页 > 代码库 > Spring Boot入门——thymeleaf模板使用

Spring Boot入门——thymeleaf模板使用

使用步骤

1、在pom.xml中引入thymeleaf

    <!-- thymeleaf插件 -->
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-thymeleaf</artifactId>
        <version>1.5.3.RELEASE</version>
    </dependency>    

2、关闭thymeleaf缓存

  创建application.properties资源文件

<!-- 关闭thymeleaf缓存 -->
spring.thymeleaf.cache=false

#spring.thymeleaf.prefix=classpath:/templates/  

#spring.thymeleaf.suffix=.html 

#spring.thymeleaf.mode=HTML5

#spring.thymeleaf.encoding=UTF-8  

# ;charset=<encoding> is added 

#spring.thymeleaf.content-type=text/html 

3、编写thymeleaf模板文件

4、编写模板请求controller

Spring Boot入门——thymeleaf模板使用