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

2020-01-09  本文已影响0人  Joiant

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.测试

上一篇下一篇

猜你喜欢

热点阅读