6月 192015
 

Spring considers that anything behind the last dot is a file extension such as .jsonor .xml and trucate it to retrieve your parameter.

So if you have /somepath/{variable} :

  • /somepath/param, /somepath/param.json, /somepath/param.xml or /somepath/param.anything will result in a param with value param
  • /somepath/param.value.json, /somepath/param.value.xml or /somepath/param.value.anything will result in a param with value param.val

翻译下就是sprng会将任何在最后一个”.”字符后的部分当作文件类型并截断。

解决方法如下:

1.  将匹配路径有原来的 /path/{variable} 修改为  /path/{variable}/   ,即最后添加/, 虽然简单但也要求请求时需要最后的/ 

2.  将匹配路径有原来的 /path/{variable} 修改为 /path/{variable:.+} , 及使用正则表达式

3.  如果项目不需要通过后缀区分类型, 可修改配置文件,修改RequestMappingHandlerMapping类属性useSuffixPatternMatch为false
<bean class=”org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping”>
        <property name=”useSuffixPatternMatch” value=”false”/>
    </bean>

done!

Sorry, the comment form is closed at this time.