Spring Boot 静态页面路径
Spring boot的环境搭建和项目创建前一章节已经讲过,这一章节就直接在上一章创建的项目中学习如果生成页面。
Spring boot的静态页面的根路径规定在src/main/resources下的public文件夹下,里面可创建子文件夹,文件格式是html后缀。访问时直接用html后缀访问。
首先要显示纯静态html页面,在项目的src/main/resources下创建public文件夹,在public下创建一个hello.html页面。
[例3-1]hello.html
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>第1个静态页面</title>
</head>
<body>
spring boot的第1个静态页面
</body>
</html>
图3-1 public下创建第1个静态页面
Src/main/java/com.example.demo/HelloApplication.java上右键→Run As→Java Application,运行后访问:http://localhost:8080/hello.html
图3-2 第1个静态页面