【发布时间】:2022-01-16 21:40:46
【问题描述】:
我使用 thymeleaf 作为前端,使用 springboot 作为后端。但 当我在注册控制器中返回我的 register.html 页面时,然后运行 应用程序 。在我的 chrome 浏览器中点击 localhost:8080 时 显示错误 404,找不到页面。我将我的设计页面定义在 模板文件夹 这是项目结构
StudentController.kt
@GetMapping("/")
fun home(student: Student, model: Model):String{
model.addAttribute("courses",courses)
return "register"
}
/**Registration API for Student Registration*/
@PostMapping("/register")
fun register(@ModelAttribute("student")student: Student, model: Model):String{
println("Details of the course Details ${student.course}")
studentService.saveStudent(student)
return "welcome"
}
当我点击 localhost:8080 时,它会显示以下错误类型
Whitelabel Error Page
This application has no explicit mapping for /error, so you are seeing this as a fallback.
Mon Dec 13 17:09:34 IST 2021
There was an unexpected error (type=Not Found, status=404).
【问题讨论】:
-
我认为您没有任何根路径“/”的映射。 404 错误通常意味着服务器找不到给定路径的响应
-
另外,当 Spring boot 遇到错误时,它会寻找映射到 /error 的视图。在您的情况下,也添加一个 error.html 模板
标签: spring-boot thymeleaf