Spring Servlet 从 *.html 映射到 SO 类型映射

发布于 2024-11-07 21:41:33 字数 381 浏览 0 评论 0原文

我有一个 Spring 应用程序,其中一个 servlet 的 url 映射为 *.html。一切都与我带注释的控制器配合得很好。

我的问题是如何设置 servlet 和带注释的映射来模仿 StackOverflow 等 url?

我想访问一个无扩展名的网址,如果可能的话,在最后的 / 之后添加描述。

示例:

我目前有:

/appName/parm1/parm2/pageName.html

我想要

/appName/parm1/parm2/pageName/description

这可能吗?我需要对带注释的控制器做什么?

谢谢

I have a spring app with one servlet that has url-mapping of *.html. Everything is working great with my annotated controllers.

My question is how can I setup my servlet and annotated mappings to mimic the urls like StackOverflow?

I would like to go to a no extension url and if possible add a description after the final /.

Example:

I currently have:

/appName/parm1/parm2/pageName.html

I would like to have

/appName/parm1/parm2/pageName/description

Is this possible and what do I need to do to my annotated controllers?

Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

终止放荡 2024-11-14 21:41:33

您应该能够将调度程序 servlet 映射到 /* 或类似的内容,然后使用 @PathVariables 从 URI 获取所需的信息。看看 http://static.springsource .org/spring/docs/current/spring-framework-reference/html/mvc.html 并搜索@PathVariable。下面是该页面的一个示例

@RequestMapping(value="/owners/{ownerId}/pets/{petId}", method=RequestMethod.GET)
public String findPet(@PathVariable String ownerId, @PathVariable String petId, Model model) {
  Owner owner = ownerService.findOwner(ownerId);  
  Pet pet = owner.getPet(petId);  
  model.addAttribute("pet", pet);  
  return "displayPet"; 
}

,它从请求 uri 中读取ownerId 和petId。

You should be able to map the dispatcher servlet to /* or something like that, and then use @PathVariables to get the needed information from the URI. Have a look at http://static.springsource.org/spring/docs/current/spring-framework-reference/html/mvc.html and search for @PathVariable. Here's an example from that page

@RequestMapping(value="/owners/{ownerId}/pets/{petId}", method=RequestMethod.GET)
public String findPet(@PathVariable String ownerId, @PathVariable String petId, Model model) {
  Owner owner = ownerService.findOwner(ownerId);  
  Pet pet = owner.getPet(petId);  
  model.addAttribute("pet", pet);  
  return "displayPet"; 
}

which reads the ownerId and the petId from the request uri.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文