如何在Spring应用中走出这个误区

gywdnpxw  于 2022-10-30  发布在  Spring
关注(0)|答案(1)|浏览(193)
@PostMapping("/addStudent")
String addStudent(@ModelAttribute("student") Students student, Model model) {
  studentsRepository.save(student);

  return "index";
}

这段代码没有返回到索引页,而是给出了一个错误:

This application has no explicit mapping for /error, so you are seeing this as a fallback.

Tue Oct 18 20:32:54 IST 2022
There was an unexpected error (type=Internal Server Error, status=500).
jdzmm42g

jdzmm42g1#

您可以尝试@控制器建议
和@异常处理程序
然后返回错误页面
参考文档:https://www.baeldung.com/exception-handling-for-rest-with-spring

相关问题