一、配置静态页面
1、pom.xml中添加模板配置
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
2、application.properties中添加静态文件查找目录
# 定位模板的目录
spring.mvc.view.prefix=classpath:/templates/
# 给返回的页面添加后缀名
spring.mvc.view.suffix=.html
3、controller文件
@GetMapping("/index") //根据application.properties添加的配置,查找index文件
public String index(){
return "home"; //当浏览器输入/index时,会返回 /templates/home.html页面
}
4、在templates新建html静态页面,示例代码
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8"/>
<title>Title</title>
</head>
<body>
<h1>123456789</h1>
<button>attack</button>
</body>
</html>
5、浏览器输入
http://localhost:8080
网友评论