目录
2、打开application.properties,添加如下配置
项目结构如图
在原有的项目resouces目录下创建static包,并在static下创建pages,然后在pages包下index.html.
index.html内容
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8"/>
<title>测试</title>
</head>
<body>
?? ?<h1>springboot访问html页面</h1>
</body>
</html>
spring.mvc.view.prefix=/pages/
spring.mvc.view.suffix=.html
package com.example.demo.controller;
?
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
?
?
@Controller
public class IndexController {
?
? ? @GetMapping("/")
? ? public String Index() {
? ? ? ? return "index";
? ? }
}