4、SpringBoot2.x整合模板引擎thymeleaf实战
    讲解:SpringBoot2.x整合模板引擎thymeleaf实战

    官网地址:https://www.thymeleaf.org/doc/articles/thymeleaf3migration.html
    1、thymeleaf相关maven依赖
            <dependency>
                   <groupId>org.springframework.boot</groupId>
                   <artifactId>spring-boot-starter-thymeleaf</artifactId>
            </dependency>

    2、thymeleaf基础配置

        #开发时关闭缓存,不然没法看到实时页面
        spring.thymeleaf.cache=false
        spring.thymeleaf.mode=HTML5
        #前缀
        spring.thymeleaf.prefix=classpath:/templates/
        #编码
        spring.thymeleaf.encoding=UTF-8
        #类型
        spring.thymeleaf.content-type=text/html
        #名称的后缀
        spring.thymeleaf.suffix=.html

    3、建立文件夹
        1)src/main/resources/templates/tl/
        2)建立一个index.html

    4、简单测试代码编写和访问
        注意:$表达式只能写在th标签内部
        快速入门:https://www.thymeleaf.org/doc/articles/standarddialect5minutes.html

开始 


配置文件

配置的跟路径直接指名了是templates下的tl文件夹作为根路径

controller


启动应用


把templates文件夹加入到springboot的默认加载路径里面去。在application.properties这里spring.resources.static-locations里面配置

所以需要把templates也加入到配置中。这样templates文件就会作为springboot默认加载会扫描加载的静态资源文件

取数据,跳转到静态页

th:text:模板语法替换了测试内容

直接访问静态页

快速入门:https://www.thymeleaf.org/doc/articles/standarddialect5minutes.html




 

相关文章:

  • 2022-12-23
  • 2021-11-12
  • 2022-02-17
  • 2021-04-24
  • 2021-11-19
  • 2022-01-01
  • 2022-03-03
猜你喜欢
  • 2021-08-12
  • 2022-02-24
  • 2021-06-23
  • 2022-03-02
  • 2022-12-23
  • 2021-10-06
  • 2021-12-10
相关资源
相似解决方案