我有一个 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/