15 springboot项目——thymeleaf语法与关闭模板引擎

15.1 thymeleaf语法

        在html文件中,有些是需要使用本地的css样式,使用thymeleaf语法加载:

        首先对head标签上面的html标签进行更改:

<html lang="en" xmlns:th="http://www.thymeleaf.org">

        其次,导入thymeleaf依赖:

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-thymeleaf</artifactId>
        </dependency>

        接着,使用thymeleaf语法:

        碰到href或者src后边与静态资源有关的的本地路径要进行修改,把要使用thymeleaf格式的属性前加入th:,等号后面改为"@{static下的路径(static不用写)}"。

         

<link th:href="@{/css/bootstrap.min.css}" rel="stylesheet">

15.2 关闭模板引擎

        在application.yaml中加入:

spring:
  thymeleaf:
    cache: false

猜你喜欢

转载自blog.csdn.net/no996yes885/article/details/132082870
今日推荐