美文网首页
【2020-01-09】 Springboot2.x整合thym

【2020-01-09】 Springboot2.x整合thym

作者: Joiant | 来源:发表于2020-01-09 19:52 被阅读0次

    1.pom.xml引入依赖

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

    2.项目目录结构

    具体见图


    springboot整合thymeleaf-1.png

    3.application.yml配置

    spring:
      thymeleaf:
        mode: HTML
        
    

    4.创建index.html

    路径:/resources/templates/index.html

    <!DOCTYPE html>
    <html>
    <head>
    <meta charset="UTF-8">
    <title>Insert title here</title>
    </head>
    <body>
        <div>
            MESSAGE: <span th:text="${message}"></span>
        </div>
    </body>
    </html>
    

    5.创建controller

    package com.ybhy.controller;
    
    import org.springframework.stereotype.Controller;
    import org.springframework.ui.Model;
    import org.springframework.web.bind.annotation.GetMapping;
    
    @Controller
    public class IndexController {
        
        @GetMapping("/")
        public String index(Model model) {
            model.addAttribute("message", "Building...");
            return "index";
        }
    
    }
    
    

    6.测试

    相关文章

      网友评论

          本文标题:【2020-01-09】 Springboot2.x整合thym

          本文链接:https://www.haomeiwen.com/subject/jxluactx.html