Spring MVC @PathVariable with dot (.) is getting truncated

后端 未结 17 1317
被撕碎了的回忆
被撕碎了的回忆 2020-11-22 06:00

This is continuation of question Spring MVC @PathVariable getting truncated

Spring forum states that it has fixed(3.2 version) as part of ContentNegotiationManager.

17条回答
  •  孤独总比滥情好
    2020-11-22 06:43

    If you are using Spring 3.2+ then below solution will help. This will handle all urls so definitely better than applying regex pattern in the request URI mapping to allow . like /somepath/{variable:.+}

    Define a bean in the xml file

    
            
            
        
    

    The flags usage can be found on the documentation. I am putting snipped to explain

    exlanation of useRegisteredSuffixPatternMatch is said to be resolving the issue. From the java doc in the class

    If enabled, a controller method mapped to "/users" also matches to "/users.json" assuming ".json" is a file extension registered with the provided {@link #setContentNegotiationManager(ContentNegotiationManager) contentNegotiationManager}. This can be useful for allowing only specific URL extensions to be used as well as in cases where a "." in the URL path can lead to ambiguous interpretation of path variable content, (e.g. given "/users/{user}" and incoming URLs such as "/users/john.j.joe" and "/users/john.j.joe.json").

提交回复
热议问题