我正在尝试使用Springboot(JPA,H2)和Thymeleaf构建我的第一个Web应用程序。
我的目标是通过控制器(controllers/
)获取存储在数据库(entities/
)中的数据。
但是,家用路线不起作用。
您能告诉我并向我解释我做错了什么吗?我忘记了配置某些东西?
感谢您的帮助!
错误
url: 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
indexController
@RestController
@RequestMapping("/")
public class IndexController {
@GetMapping(value = "/")
public ModelAndView getHome(){
ModelAndView mv = new ModelAndView();
mv.setViewName("index");
return mv;
}
}
index.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作为项目的依赖项包括在内。
本指南可能会有所帮助
当应用程序启动时,请查看其日志并找到
之类的映射2019-03-08 17:52:24.864 INFO 9592 --- [ main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/greeting]}" onto public hello.Greeting hello.GreetingController.greeting(java.lang.String)
这意味着您可以使用/问候来调用URL,并将其映射到通讯控制器
404错误意味着您调用未映射的URL