url结尾最后一个点后的内容会被忽略解释


请求http://127.0.0.1/name/4.003
java代码中/name/{version}
在接口中解析到的version为4
解决办法:将该参数以param的形式传递,
即http://127.0.0.1/name?version=4.003

这是因为Spring MVC自动的路径解析策略,
会根据后缀名来决定请求的视图类型,具体配置如下

<bean id="contentNegotiationManager" class="org.springframework.web.accept.ContentNegotiationManager">
<constructor-arg>
    <array>
        <bean class="org.springframework.web.accept.HeaderContentNegotiationStrategy"/>
        <!-- 根据后缀名来决定请求的视图类型 -->
        <bean class="org.springframework.web.accept.PathExtensionContentNegotiationStrategy">
            <constructor-arg>
                <map>
                    <entry key="xml" value="application/xml" />
                    <entry key="json" value="application/json" />
                    <entry key="html" value="text/html" />
                    <entry key="htm" value="text/html" />
                    <entry key="txt" value="text/plain" />
                    <entry key="xls" value="application/vnd.ms-excel" />
                </map>
            </constructor-arg>
        </bean>
    </array>
</constructor-arg>
</bean>
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容