• Spring Boot 初体验(9)使用thymeleaf


    步骤:在pom.xml中引入thymeleaf

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

    关于thymeleaf的相关配置

    ########################################################
    ###THYMELEAF (ThymeleafAutoConfiguration)
    ########################################################
    #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 
    # set to false for hot refresh 开发时设置不用缓存,生产环境设置为true
    spring.thymeleaf.cache=false  

    开始使用:

    编写模板文件 :默认都放在  src/main/resouces/templates文件夹下

            例如:src/main/resouces/templates/hello.html

    示例代码: 

    package com.mt.controller;
    
    import java.util.Date;
    import java.util.Map;
    
    import org.springframework.stereotype.Controller;
    import org.springframework.web.bind.annotation.RequestMapping;
    
    @Controller
    @RequestMapping("/thymeleaf")
    public class ThymeleafController {
        @RequestMapping("/hello")
        public String hello(Map<String, Object> map) {
            map.put("date", new Date());
            return "thymeleafDemo";
        }
    }
    <!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 thymeleaf!</title>
        </head>
        <body>
            <h1 th:inline="text">Hello.v.2</h1>
            <p th:text="${date}"></p>
        </body>
    </html>

    一个走投无路的庄稼汉
  • 相关阅读:
    nginx访问控制
    nginx的请求限制
    nginx目录及配置语法
    安装Nginx
    Docker Service启动时挂载docker命令
    禁止flyme自动下载rom
    docker.service 修改指南
    debian 10.x (buster) 离线安装docker及卸载
    按照容器名称清除docker容器产生的日志文件内容
    debian修改系统语言为英文
  • 原文地址:https://www.cnblogs.com/kuangyefeige/p/9892672.html
Copyright © 2020-2023  润新知