zoukankan      html  css  js  c++  java
  • 使用thymeleaf

    操作步骤
    (1)在pom.xml中引入thymeleaf;
    (2)如何关闭thymeleaf缓存
    (3)编写模板文件.html
    (4)编写访问模板文件controller
     
    在pom.xml加入thymeleaf的依赖:
    <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-thymeleaf</artifactId>
    </dependency>
     
    如何关闭thymeleaf缓存
    spring.thymeleaf.cache=false
     
     
    编写模板文件src/main/resouces/templates/hello.html:
    <!DOCTYPE html>
    <html xmlns="http://www.w3.org/1999/xhtml" xmlns:th="http://www.thymeleaf.org"
          xmlns:sec="http://www.thymeleaf.org/thymeleaf-extras-springsecurity3">
        <head>
            <title>Hello World!</title>
        </head>
        <body>
            <h1 th:inline="text">Hello.v.2</h1>
            <p th:text="${hello}"></p>
        </body>
    </html>
     
     
    编写访问模板文件controller
    @Controller
    public class TemplateController {
     
      /**
       * 返回html模板.
       */
      @RequestMapping("/helloHtml")
      public String helloHtml(Map<String,Object> map){
      map.put("hello","from TemplateController.helloHtml");
      return "/helloHtml";
      }
     
    }
  • 相关阅读:
    Win10 rocketmq 安装
    Vulnhub DC7
    Vulnhub DC6
    Vulnhub DC5
    Vulnhub DC4
    Vulnhub DC3
    一文带你学会CSRF漏洞
    Shiro反序列化漏洞复现与实战
    DataPipeline CPO 陈雷:实时数据融合之法:便捷可管理
    DataPipeline合伙人 & CPO 陈雷:企业实时数据管理问题与实践 | 附PPT下载
  • 原文地址:https://www.cnblogs.com/YangBinChina/p/13784855.html
Copyright © 2011-2022 走看看