禁用在Spring 3.2中修剪路径变量中的空格 [英] Disable trimming of whitespace from path variables in Spring 3.2

查看:90
本文介绍了禁用在Spring 3.2中修剪路径变量中的空格的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

默认情况下,Spring会从用作路径变量的字符串中修剪前导/尾随空格。我跟踪这是因为 trimTokens 标志默认设置为 true AntPathMatcher

By default, Spring trims leading/trailing whitespace from strings used as path variables. I've tracked this down to be because the trimTokens flag is set to true by default in AntPathMatcher.

但是,我无法弄清楚如何将该标志设置为 false

What I can't figure out, though, is how to set that flag to false.

提供我的使用 AntPathMatcher 拥有 RequestMappingHandlerMapping bean,我将其设置为 false 不起作用。

Providing my own RequestMappingHandlerMapping bean using an AntPathMatcher where I set it to false didn't work.

如何使用JavaConfig更改此标志?

How do I change this flag using JavaConfig?

谢谢。

推荐答案

让你的配置扩展 WebMvcConfigurationSupport 覆盖 requestMappingHandlerMapping()并相应地进行配置。

Let your configuration extend WebMvcConfigurationSupport override requestMappingHandlerMapping() and configure accordingly.

@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;
    }
} 

这篇关于禁用在Spring 3.2中修剪路径变量中的空格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆