【发布时间】:2018-08-02 19:16:26
【问题描述】:
我正在使用 Spring MVC 并试图了解控制器/视图部分的工作原理,但我在“/”和我尝试的任何其他路由上都收到 404 错误。
我尝试将@EnableWebMVC 添加到我的主类中,但这给了我一个500 错误Could not resolve view with name 'index' in servlet with name 'dispatcherServlet' 和一个异常,如下所列。
我的控制器:
public class MyController {
@RequestMapping("/")
public String index(Model model) {
return "index";
}
}
我有两个 /src/main/resources/static/index.html /.../resources/templates/index.html ,因为我还是 Spring/Thymeleaf 的新手,我不确定哪个应该工作
Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Could not resolve view with name 'index' in servlet with name 'dispatcherServlet'] with root cause
javax.servlet.ServletException: Could not resolve view with name 'index' in servlet with name 'dispatcherServlet'
【问题讨论】:
标签: java spring model-view-controller thymeleaf