
正文
Spring Boot 静态页面跳转
提示:扫一扫查出行【扫一扫了解最新限行尾号】
复制提示
本篇博客仅为自己提个醒:如何跳转页面而不麻烦控制器。
当我们创建 Spring Boot 项目时(勾选了 Thymeleaf 和 Web),目录结构会是如下:
其中图二是我创建了一个 html 文件夹以及一个 index.html 页面。
如果要实现静态页面的跳转(不经过控制器),静态文件必须放在 static 目录下。
因为访问 templates 目录下的文件都需要经过控制器。
index.html
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
<a href="/html/login.html">登录</a>
</body>
</html>
login.html
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
<form action="#">
<input type="text" name="username" placeholder="Username">
<input type="password" name="password" placeholder="Password">
<input type="submit" value="Login">
</form>
</body>
</html>
好啦,可以在浏览器输入 http://localhost:8080/ 试下了。







