【发布时间】:2026-02-05 13:05:01
【问题描述】:
我有简单的 AngularJS 单页应用程序和用于后端的 Spring Boot。我需要在不同的 URL 上返回 index.html。我创建了这种控制器:
@Controller
public class WebResourcesController {
@RequestMapping(value = {"/sample", "/sample/pages"}, method = RequestMethod.GET)
public String index() {
return "index";
}
}
但对 localhost:8080/sample/pages 的请求返回状态 404。仍然当我向 localhost:8080/sample 发送请求时,我得到了正确的 html 文件和页面加载。我在resources/public 文件夹中有我的index.html。我认为 localhost:8080/sample/pages 请求试图在 sample/pages 文件夹而不是 / 中查找资源。我该如何解决这种问题?
【问题讨论】:
-
能否给出Class文件的头部(类的注解@RequestMapping)。可以有多个 url 提供相同的内容。 “索引”意味着它将加载 index.html... requestMapping 对文件没有任何操作。
标签: angularjs spring spring-mvc spring-boot