java - Spring MVC 为匹配模式的所有 url 提供相同的静态内容

标签 java spring spring-mvc

我有一个 Spring MVC 4 应用程序,我想使用相同的“/editor/index.html”资源为“/editor/**”下的所有 URL 提供服务。

我正在使用 EmberJS 和 History API,因此像/editor/task/1 这样的请求实际上并不是一个 URL,它只是一个应该发送到/editor/index.html 的历史 URL,它会处理它。

我尝试使用

<mvc:resources mapping="/editor/**" location="/editor/"/>

但这不起作用,它会将“/editor/task/1”等后续 URL 发送到 servlet,当然它还会发送 404 资源未找到。

有没有一种方法可以使用相同的资源来提供所有网址?

最佳答案

您应该定义一个 Controller ,它为所有匹配“/editor/*”的 URL 返回相同的 View 。

@Controller
public class EditorController {
  @RequestMapping("/editor/*")
  @GET
  public String doGet() {
    return "editor/index.html";
}

关于java - Spring MVC 为匹配模式的所有 url 提供相同的静态内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28409613/

相关文章:

java - 什么是 org.eclipse.wst.common.component 以及如何将它用于 ant

java - 为什么我必须向家长提供创建客户的信息?

spring - 当请求正文未通过使用 Bean Validation/Hibernate Validator 定义的验证时,如何返回自定义响应 pojo?

java - org.springframework.beans.factory.UnsatisfiedDependencyException : Unsatisfied dependency expressed through method 'anyMethodName' parameter 0:

java - Spring MVC - 浏览器中的 URL 显示和编码支持

java - 编译时出现不兼容类型问题 - void to MimeMessage

java - OAuth2 基于角色的身份验证

spring - 将动态属性列表读入 Spring 托管 bean

java - Spring Boot Actuator - 自定义端点

Spring <mvc :resources mapping ="/css/**" location ="/css/"/> doesn't work