Ran*_*niz 5 java spring spring-mvc
默认情况下,Spring 会修剪用作路径变量的字符串中的前导/尾随空格。我发现这是因为AntPathMatcher中的trimTokens标志默认设置为true。
但我不知道如何将该标志设置为false。
使用AntPathMatcher提供我自己的RequestMappingHandlerMapping bean ,并将其设置为false不起作用。
如何使用 JavaConfig 更改此标志?
谢谢。
让您的配置扩展WebMvcConfigurationSupport覆盖requestMappingHandlerMapping()并进行相应配置。
@Configuration
public MyConfig extends WebMvcConfigurationSupport {
    @Bean
    public PathMatcher pathMatcher() {
      // Your AntPathMatcher here.
    }
    @Bean
    public RequestMappingHandlerMapping requestMappingHandlerMapping() {
        RequestMappingHandlerMapping  rmhm = super.requestMappingHandlerMapping();
        rmhm.setPathMatcher(pathMatcher());
        return rmhm;
    }
} 
| 归档时间: | 
 | 
| 查看次数: | 2888 次 | 
| 最近记录: |