【发布时间】:2013-05-27 20:54:50
【问题描述】:
我想以如下方式在网站中显示文章
example.com/articles/23/thetitle
ie example.com/articles/{id}/{title}
对于每个请求,真正重要的是 id。我将显示与 id 对应的文章,显示标题是为了便于阅读。现在的问题是,当用户在浏览器中编辑 url 时,比如从 example.com/articles/23/thetitle 到 example.com/articles/23/xyz 并重新加载,相同的内容会使用新的 url 加载。
我该如何解决这个问题?如何让我的 URL 显示为 example.com/articles/23/thetitle 条目 example.com/articles/23/{anything}
我查看了URLrewriting。但这似乎不是我的解决方案。
我能想到的唯一解决方案是用 javascript 来做,但恕我直言很脏。
我正在使用 Spring MVC。提前致谢
PS: 总而言之,我希望它能够像在 SO 中那样工作。如果我们编辑问题编号并重新加载,则会加载新标题。
这是我当前如何获取文章的代码示例
@RequestMapping(value = "/{id}/{title}", method = RequestMethod.GET)
public
String loadArticle(HttpServletRequest request,
@PathVariable Long id, Model model) {
//get the article
model.addAttribute("article", article);
return "article";
}
【问题讨论】:
标签: java spring rest spring-mvc clean-urls