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

1.pom.xml引入依赖

    
        org.springframework.boot
        spring-boot-starter-thymeleaf
    

2.项目目录结构

具体见图


springboot整合thymeleaf-1.png

3.application.yml配置

spring:
  thymeleaf:
    mode: HTML
    

4.创建index.html

路径:/resources/templates/index.html





Insert title here


    
MESSAGE:

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整合thymeleaf)