springboot(一) thymeleaf配置

文件目录结构如下:
在这里插入图片描述
HelloController中的代码如下:

package com.example.demo.Controller;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

@Controller
public class HelloController {

    @RequestMapping("/hello")
    public String hello()
    {
        return "hello";
    }
}

在pom.xml中添加依赖:

<!-- 导入thymeleaf模版 的依赖-->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-thymeleaf</artifactId>
        </dependency>

并右键单击pom.xml→Maven→点击 Reimport
在这里插入图片描述
在templates文件夹下添加hello.html
在这里插入图片描述
代码:

<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>springboot-thymeleaf demo</title>
</head>
<body>
good job!!!
</body>
</html>
</html>

点击运行,在网页中查看:
在这里插入图片描述
结果:
在这里插入图片描述

发布了53 篇原创文章 · 获赞 18 · 访问量 1万+

猜你喜欢

转载自blog.csdn.net/YUEXILIULI/article/details/103053382