thymeleaf使用

thymeleaf使用

1.依赖

    <parent>
        <artifactId>spring-boot-starter-parent</artifactId>
        <groupId>org.springframework.boot</groupId>
        <version>2.1.6.RELEASE</version>
    </parent>

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

2.配置前缀后缀

    spring:
      thymeleaf:
      prefix: classpath:/templates/
      suffix: .html
      cache: false # 开发时禁用缓存

3.在resource下新建目录

  • 新写的html页面都放在此处
  • 记得新建的html文件加上名称空间
    
      <!DOCTYPE html>
      <html xmlns:th="http://www.thymeleaf.org">
        <head>
            <meta charset="UTF-8">
            <title>test1</title>
        </head>
        <body>
                <h1><span>test1.........</span></h1>
        </body>
      </html>
    

4.基础用法:

  • 修改标签文本值 th:text=""



posted @ 2022-05-03 11:46  锅巴编程  阅读(48)  评论(0)    收藏  举报