pom.xml添加依赖

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

resources目录下新建templates目录,存放html页面,比如 index.html

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8"/>
    <title>Title</title>
</head>
<body>
<h1>这个是第一个springboot访问页面</h1>
</body>
</html>

resources>application.properties配置文件
SpringBoot项目访问html页面

spring.thymeleaf.prefix=classpath:/templates/

编写控制层java>controller>indexController:

package controller;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.Map;

@Controller
@EnableAutoConfiguration
public class indexController {

    @RequestMapping("/index")
    public String index(){
        return "/index";
    }
    
    public static void main(String[]args){
        SpringApplication.run(indexController.class,args);
    }

}

目录如下:
SpringBoot项目访问html页面

最终执行main函数,浏览器输入localhost:8080/index
SpringBoot项目访问html页面

相关文章: