java - 如何配置 Spring/Springboot 访问主页?
问题描述
我正在尝试使用 Springboot(JPA、H2)和 Thymeleaf 构建我的第一个 Web 应用程序。
entities/
我的目标是通过控制器( )获取/修改/删除存储到数据库( )中的数据controllers/
。
但是,家乡路线不起作用。
你能告诉我并解释我做错了什么吗?我忘了配置什么?
感谢帮助!
错误
网址:localhost:8082/
Whitelabel Error Page
This application has no explicit mapping for /error, so you are seeing this as a fallback.
Fri Mar 08 14:22:21 CET 2019
There was an unexpected error (type=Not Found, status=404).
No message available
索引控制器
@RestController
@RequestMapping("/")
public class IndexController {
@GetMapping(value = "/")
public ModelAndView getHome(){
ModelAndView mv = new ModelAndView();
mv.setViewName("index");
return mv;
}
}
索引.html
<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
<meta charset="UTF-8">
<title>Home</title>
<link rel="stylesheet" href="../static/css/bootstrap.min.css">
</head>
<body>
<p>Test</p>
</body>
</html>
文件夹
projetname/
|__src/
|__main/
|__java/
|__projectname/
| |__controllers/
| | |__IndexController.java
| |__entities/
| |__repositories/
| |__App.java
|__resources/
|__static/
| |__css/
| |__js/
|__templates/
| |__index.html
|__data.sql
|__application.properties
解决方案
确保 spring-boot-starter-thymeleaf 作为项目的依赖项包含在内。
推荐阅读
- azure-devops - TFS xaml build vs TFS vNext build vs Octopus Deploy 的可维护性
- c# - 制作高大堆物体的最有效方法?
- regex - 如何在 bash 脚本的 grep 正则表达式字符串中使用变量
- android - 在 Flutter 项目上创建 Android 库
- oracle - Oracle DBMS_LOB.WRITEAPPEND 到 Postgres 的转换
- c# - 支持 IComparable 时的比较语法
- angular - Angular Material 主题问题
- jenkins - 在声明性管道的并行阶段重用代理
- sql - 如何通过将数字替换为 NULL 值并自动递增以下数字来更新 SQL Server 表?
- java - 从firebase数据库设置图像的墙纸按钮