如何更改Spring MVC处理url'dot'字符的行为 [英] How to change Spring MVC's behavior in handling url 'dot' character

查看:143
本文介绍了如何更改Spring MVC处理url'dot'字符的行为的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将一个Web项目从Jersey迁移到Spring MVC 3.0。直到我开始使用点符号迁移应该处理URL的控制器时,这个过程非常简单:/ myApp / resources / create / root.subFolder1 。 Spring MVC似乎无耻地从URL中删除了。subFolder1部分,它发生在框架代码内部(参见 AbstractUrlHandlerMapping 类)

I'm trying to migrate a web project off from Jersey to Spring MVC 3.0. The process was really straightforward up to the moment when I started to migrate the controllers supposed to handle URL's with dot notations: "/myApp/resources/create/root.subFolder1". Spring MVC seems to shamelessly cut the ".subFolder1" part from the URL, which happens deep inside framework code (see AbstractUrlHandlerMapping class)

uriTemplateVariables.putAll(getPathMatcher().extractUriTemplateVariables(matchingPattern, urlPath));

所以我的控制器方法用 root 路径参数调用,而不是 root.subFolder1

So my controller method gets invoked with root path parameter, not root.subFolder1

我真的想找到一种方法来自定义此行为。有什么建议吗?

I'd really like to find a way to customize this behavior. Any advices?

PS。要求有点保持现有的URL结构,即切换到查询参数/ myApp / resources / create / ?path = root.subFolder1 等变通方法。我不能考虑。

PS. The requirement is kinda to keep the existing URL structure, i.e. workarounds like switching to query params "/myApp/resources/create/?path=root.subFolder1" I cannot consider.

PS。我的Spring配置看起来像

PS. My Spring config looks like

<mvc:annotation-driven/>

<bean class="org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping">
    <property name="useDefaultSuffixPattern" value="false" />
</bean>

<context:component-scan base-package="my.app.pkg"/>


推荐答案

在某些情况下可能更容易的另一种可能性是在网址末尾添加一个尾随的 /

Another possibility which may be easier in some circumstances is to add a trailing / to the end of the URL.

所以你的网址将是 /myApp/resources/create/root.subFolder1 /

这可以在我的应用程序中使用Spring MVC 3.1。

This works in my app using Spring MVC 3.1.

这篇关于如何更改Spring MVC处理url'dot'字符的行为的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆