默认情况下,Spring 会从用作路径变量的字符串中删除前导/尾随空格。我发现这是因为 trimTokens 标志在 AntPathMatcher 中默认设置为 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;
}
}
关于java - 在 Spring 3.2 中禁用路径变量中的空格修剪,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21047104/